Digital Signal Processing Reference
In-Depth Information
// FIR4ways.c FIR with alternative ways of storing/updating samples
#include "DSK6713_AIC23.h" //codec-DSK file support
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;//set sampling rate
#include "bp41.cof" //BP coeff centered at Fs/8
#define METHOD 'A' //change to B or C or D
int yn = 0; //initialize filter's output
short dly[N+1]; //delay samples array(one extra)
interrupt void c_int11()
//ISR
{
short i;
yn = 0; //initialize filter's output
#if METHOD == 'A' //if 1st method
dly[0] = input_sample(); //newest sample @ top of buffer
for (i = 0; i< N; i++)
yn += (h[i] * dly[i]); //y(n)=h[0]*x[n]+..+h[N-1]x[n-(N-1)]
for (i = N-1; i > 0; i--) //from bottom of buffer
dly[i] = dly[i-1]; //update sample data move "down"
#elif METHOD == 'B' //if 2nd method
dly[0] = input_sample(); //newest sample @ top of buffer
for (i = N-1; i >= 0; i--) //start @ bottom to convolve
{
yn += (h[i] * dly[i]); //y=h[N-1]x[n-(N-1)]+...+h[0]x[n]
dly[i] = dly[i-1]; //update sample data move "down"
}
#elif METHOD == 'C' //use xtra memory location
dly[0] = input_sample(); //newest sample @ top of buffer
for (i = N-1; i>=0; i--) //start @ bottom of buffer
{
yn += (h[i] * dly[i]); //y=h[N-1]x[n-(N-1)]+...+h[0]x[n]
dly[i+1] = dly[i]; //update sample data move "down"
}
#elif METHOD == 'D' //1st convolve before loop
dly[N-1] = input_sample(); //newest sample @ bottom of buffer
yn = h[N-1] * dly[0]; //y=h[N-1]x[n-(N-1)] (only one)
for (i = 1; i<N; i++) //convolve the rest
{
yn +=(h[N-(i+1)]*dly[i]); //h[N-2]x[n-(N-2)]+...+h[0]x[n]
dly[i-1] = dly[i]; //update sample data move "up"
}
#endif
output_sample((short)(yn>>15)); //output filter
return;
//return from ISR
}
void main()
{
comm_intr(); //init DSK, codec, McBSP
while(1); //infinite loop
}
FIGURE 4.26. FIR program using four alternative methods for convolution and updating
of delay samples ( FIR4ways.c ).
Search WWH ::




Custom Search