Reputation: 183
I am developing a low pass biquad filer for an embedded system. Searching for examples in C, I came up to this link on Stanford University's website: https://ccrma.stanford.edu/~jos/filters/Biquad_Software_Implementations.html. After adding the code to my filter.c file in my Eclipse project, I get these build errors:
1- Syntax error on "typedef word double".
2- Type 'word' could not be resolved (for s2, s1, gain, a2, a1, b2, and b1 in "typedef struct _biquadVars").
3- Type 'dbl' could not be resolved (for "A" in "void biquad(biquadVars *a)").
4- Type 'word' could not be resolved (for "s0" in "void biquad(biquadVars *a)").
5- Symbol "NTICK" could not be resolved (in "void biquad(biquadVars *a)").
What I did:
1- Changed "typedef word double;" to "typedef double word;". This resolved the related error. 2- Changed "dbl A;" to "double A;". Obviously helpful.
Questions:
1- Should I trust the original article and search more on why "word" has been chosen over "double"? Or is "dbl" a type that I'm not aware of?
2- Any idea what NTICK might be?
Thanks.
EDIT (added the sample code):
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;
}
}
Upvotes: 2
Views: 1640
Reputation: 23218
Usage of typedef
is typedef <native C type> <alias symbol>
where the purpose is often to map a native C type
symbol to some new symbol to improve readability or relevance within a particular code base. In this case, the arguments are simply reversed:
typedef word double;//two issues, word is not a native type, double is, reverse them.
Should be
typedef double word; creates a new type 'word', equivalent to double
Note also on this point, the following would also be problematic:
typedef double int;//attempting to typedef to a native type is not allowed
Resulting in an error similar to: cannot combine with previous 'double' declaration specifier
And, the following has no syntactical errors, it is fine:
typedef double * pp; //creates a new type pp equivalent to double *
There is no native type dbl
, it is likely a typo in the article. It never hurts to look at several sources for such algorithms. Try to include peer reviewed articles if you have access to them, i.e. from sources such as IEEE.
Cannot be sure, but given its usage context
for (i=0; i<NTICK; i++) {
it is likely a #define
of some value of maximum ticks. i.e. for 1000 clock ticks
#define NTICK 1000
Upvotes: 3