Next |
Prev |
Up |
Top
|
Index |
JOS Index |
JOS Pubs |
JOS Home |
Search
In matlab, an efficient FIR filter is implemented by calling
outputsignal = filter(B,1,inputsignal);
where
It is relatively efficient because filter is a built-in
function (compiled C code in most matlab implementations). However,
for FIR filters longer than a hundred or so taps, FFT
convolution should be used for maximum speed. In Octave and the
Matlab Signal Processing Toolbox, fftfilt implements FIR
filters using FFT convolution (say ``help fftfilt'').
Figure 5.6 lists a second-order FIR filter implementation in the
C programming language.
Figure 5.6:
C code for implementing a length 3 FIR filter.
typedef double *pp; // pointer to array of length NTICK
typedef double word; // signal and coefficient data type
typedef struct _fir3Vars {
pp outputAout;
pp inputAinp;
word b0;
word b1;
word b2;
word s1;
word s2;
} fir3Vars;
void fir3(fir3Vars *a)
{
int i;
word input;
for (i=0; i<NTICK; i++) {
input = a->inputAinp[i];
a->outputAout[i] = a->b0 * input
+ a->b1 * a->s1 + a->b2 * a->s2;
a->s2 = a->s1;
a->s1 = input;
}
}
|
Next |
Prev |
Up |
Top
|
Index |
JOS Index |
JOS Pubs |
JOS Home |
Search
[How to cite this work] [Order a printed hardcopy] [Comment on this page via email]