Digital Signal Processing Reference
In-Depth Information
// Aliasing.c illustration of downsampling, aliasing, upsampling
#include "DSK6713_AIC23.h" //codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;//set sampling rate
#include "lp33.cof" //lowpass at 1.9 kHz
short flag = 0; //toggles for 2x down-sampling
short indly[N],outdly[N]; //antialias and reconst delay lines
float yn; int i; //filter output, index
short antialiasing = 0; //init for no antialiasing filter
interrupt void c_int11()
//ISR
{
indly[0]=(float)(input_sample());//new sample to antialias filter
yn = 0.0; //initialize downsampled value
if (flag == 0) flag = 1; //don't discard at next sampling
else
{
if (antialiasing == 1) //if antialiasing filter desired
{ //compute downsampled value
for (i = 0 ; i < N ; i++) //using LP @ 1.9 kHz filter coeffs
yn += (h[i]*indly[i]); //filter is implemented using float
}
else //if filter is bypassed
yn = indly[0]; //downsampled value is input value
flag = 0; //next input value will be discarded
}
for (i = N-1; i > 0; i--)
indly[i] = indly[i-1]; //update input buffer
outdly[0] = (yn); //input to reconst filter
yn = 0.0; //4 kHz sample values and zeros
for (i = 0 ; i < N ; i++) //are filtered at 8 kHz rate
yn += (h[i]*outdly[i]); //by reconstruction lowpass filter
for (i = N-1; i > 0; i--)
outdly[i] = outdly[i-1]; //update delays
output_sample((short)yn); //8kHz rate sample
return; //return from interrupt
}
void main()
{
comm_intr(); //init DSK, codec, McBSP
while(1); //infinite loop
}
FIGURE 4.29. Program to illustrate aliasing and antialiasing down-sampling to a rate of
4 kHz ( aliasing.c ).
a delayed version of the input. Increase the input signal frequency beyond 1.9 kHz
and verify that the output reduces to zero. This is due to the 1.9-kHz (at the down-
sampling rate of 4 kHz) antialiasing lowpass filter, implemented using the coefficient
file lp33.cof (on the CD). In lieu of a sinusoidal signal as input, you can use a
swept sinusoidal input signal.
Search WWH ::




Custom Search