Digital Signal Processing Reference
In-Depth Information
. . . N=256,16kHz rate,align x&w,... see Examples in Chapter 6
#include <rtdx.h>
short input_buffer[N] = {0};
//store input samples(same as x)
float output_buffer[N] = {0};
//store magnitude FFT
short buffer_count=0;
short nFlag=1;
//when to begin the FFT
short i, j;
RTDX_CreateOutputChannel(ochan);
//output channel C6x->PC transfer
interrupt void c_int11()
//ISR
{
input_buffer[buffer_count] = input_sample(); //input -->buffer
output_sample(input_buffer[buffer_count++]); //loop
if(buffer_count >= N)
{
//if more than N pts, begin FFT
buffer_count = 0;
//reset buffer_count
nFlag = 0;
//flag to signal completion
for(i = 0; i < N; i++)
{
x[2*i]=(float)input_buffer[i]; //real component of input
x[2*i+1] = 0;
//imaginary component of input
}
}
}
void main(void)
{
. . . //generate twiddle constants and digit reversal index
comm_intr(); //init DSK
while(!RTDX_isOutputEnabled(&ochan));//wait for PC to enable RTDX
while(1)
//infinite loop
{
while(nFlag);
//wait to finish accum samples
nFlag = 1;
cfftr4_dif(x, w, N); //call radix-4 FFT function
digit_reverse((double *)x, IIndex, JIndex, count);
for(j = 0; j < N; j++)
output_buffer[j]=(float)sqrt(x[2*j]*x[2*j]+x[2*j+1]*x[2*j+1]);
RTDX_write(&ochan,output_buffer,sizeof(output_buffer));//Send DSK>PC
};
}
( a )
( b )
FIGURE 10.10. ( a ) C program to implement radix-4 FFT and illustrate RTDX with Visual
C
++
, using MATLAB for FFT and plotting ( rtdx_vc_FFTr4.c ); ( b ) message when the
VC
++
application file is executed.
Search WWH ::




Custom Search