Digital Signal Processing Reference
In-Depth Information
// Fir.c FIR filter. Include coefficient file with length N
#include "bs2700.cof" //coefficient file
#include "dsk6713_aic23.h" //codec-dsk support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
int yn = 0; //initialize filter's output
short dly[N];
//delay samples
interrupt void c_int11()
//ISR
{
short i;
dly[0]=input_sample(); //input newest sample
yn = 0; //initialize filter's output
for (i = 0; i< N; i++)
yn += (h[i] * dly[i]); //y(n) += h(i)* x(n-i)
for (i = N-1; i > 0; i--) //starting @ end of buffer
dly[i] = dly[i-1]; //update delays with data move
output_sample(yn >> 15); //scale output filter sample
return;
}
void main()
{
comm_intr(); //init DSK, codec, McBSP
while(1); //infinite loop
}
FIGURE 4.5. Generic FIR filter program ( FIR.c ).
// bs2700.cof FIR bandstop coefficients designed with MATLAB
#define N 89
//number of coefficients
short h[N]= {-14,23,-9,-6,0,8,16,-58,50,44,-147,119,67,-245,
200,72,-312,257,53,-299,239,20,-165,88,0,105,
-236,33,490,-740,158,932,-1380,392,1348,-2070,
724,1650,-2690,1104,1776,-3122,1458,1704,29491,
1704,1458,-3122,1776,1104,-2690,1650,724,-2070,
1348,392,-1380,932,158,-740,490,33,-236,105,0,
88,-165,20,239,-299,53,257,-312,72,200,-245,67,
119,-147,44,50,-58,16,8,0,-6,-9,23,-14};
FIGURE 4.6. Coefficients for a FIR bandstop filter ( bs2700.cof ).
A buffer dly[N] is created for the delay samples. The newest input sample, x ( n ),
is acquired through dly[0] and stored at the beginning of the buffer. The coeffi-
cients are stored in another buffer, h [ N ], with h [0] at the beginning of the coeffi-
cients' buffer. The samples and coefficients are then arranged in their respective
buffer, as shown in Table 4.1.
Two “for” loops are used within the interrupt service routine (we will also imple-
ment an FIR filter using one loop). The first loop implements the convolution equa-
Search WWH ::




Custom Search