【问题标题】:Biquad Filter Example Implementation in CC 语言中的双二阶滤波器示例实现
【发布时间】:2020-11-19 09:13:40
【问题描述】:

我正在为嵌入式系统开发低通双二阶滤波器。在搜索 C 语言示例时,我在斯坦福大学的网站上找到了这个链接:https://ccrma.stanford.edu/~jos/filters/Biquad_Software_Implementations.html。在我的 Eclipse 项目中将代码添加到我的 filter.c 文件后,我收到以下构建错误:

1- “typedef word double”的语法错误。

2- 无法解析类型“word”(对于“typedef struct _biquadVars”中的 s2、s1、gain、a2、a1、b2 和 b1)。

3- 无法解析类型“dbl”(对于“void biquad(biquadVars *a)”中的“A”)。

4- 无法解析类型“word”(对于“void biquad(biquadVars *a)”中的“s0”)。

5- 符号“NTICK”无法解析(在“void biquad(biquadVars *a)”中)。

我做了什么:

1- 更改了“typedef word double;”为“typedef 双字;”。这解决了相关的错误。 2-更改了“dbl A;”到“双A;”。显然很有帮助。

问题:

1- 我应该相信原始文章并更多地搜索为什么选择“word”而不是“double”吗?还是“dbl”是我不知道的类型?

2- 知道 NTICK 可能是什么吗?

谢谢。

编辑(添加示例代码):

typedef double *pp;// pointer to array of length NTICK
typedef word double; // signal and coefficient data type

typedef struct _biquadVars {
    pp output;
    pp input;
    word s2;
    word s1;
    word gain;
    word a2;
    word a1;
    word b2;
    word b1;

} biquadVars;

void biquad(biquadVars *a)
{

    int i;
    dbl A;
    word s0;
    for (i=0; i<NTICK; i++) {
    
        A = a->gain * a->input[i];
        A -= a->a1 * a->s1;
        A -= a->a2 * a->s2;
        s0 = A;
        A += a->b1 * a->s1;
        a->output[i] = a->b2 * a->s2 + A;
        a->s2 = a->s1;
        a->s1 = s0;

    }
}

【问题讨论】:

  • @ryyker 谢谢,添加了代码。
  • 谢谢。请参阅下面的答案。

标签: c filter embedded signal-processing


【解决方案1】:

typedef 的用法是typedef &lt;native C type&gt; &lt;alias symbol&gt;
其目的通常是将原生 C type 符号映射到某个新符号,以提高特定代码库中的可读性或相关性。在这种情况下,参数只是颠倒了:

typedef word double;//two issues, word is not a native type, double is, reverse them.

应该是

typedef double word;  creates a new type 'word', equivalent to double  

还要注意这一点,以下也是有问题的:

typedef double int;//attempting to typedef to a native type is not allowed

导致类似于:cannot combine with previous 'double' 声明说明符的错误

而且,以下没有语法错误,很好:

typedef double * pp; //creates a new type pp equivalent to double *
  • 1- 我应该相信原始文章并更多地搜索为什么选择“word”而不是“double”吗?还是“dbl”是我不知道的类型?

没有原生类型dbl,很可能是文章中的错字。查看此类算法的多个来源永远不会有什么坏处。如果您可以访问同行评审的文章,例如来自 IEEE 等来源,请尝试包含这些文章。

  • 2- 知道 NTICK 可能是什么吗?

不能确定,但​​考虑到它的使用上下文

for (i=0; i<NTICK; i++) {

它可能是某个最大刻度值的#define。即 1000 个时钟滴答

#define NTICK 1000 

【讨论】:

  • 我们可以将 NTICK 解释为输入/输出信号缓冲区的长度吗?
  • @Alireza - 在这个函数中,是的。 a-&gt;output[] 需要定义为具有存储 NTICK 元素的内存。在其他函数中,可能有一个不同的#define 具有不同的值来确定大小。显示的代码均不包括pp outputpp input 的内存分配,所以我假设它是在调用函数中完成的。
猜你喜欢
  • 2018-10-02
  • 2016-03-22
  • 2017-03-21
  • 1970-01-01
  • 1970-01-01
  • 2012-05-23
  • 1970-01-01
  • 1970-01-01
  • 2014-05-11
相关资源
最近更新 更多