Hi Guys,
I have been stuck with this FFT stuff since long and still I am unable to verify the result. I am simply using dsk_app.c project for C6713 board and implementing DSPLIB function DSPF_sp_cfftr2_dit to compute 1024 point FFT over 1024 complex pairs of input. I am going to explain over all steps which has been a part of my implementation. Please have a look if I am wrong any where.
I defined these parts in dsk_app.c project.
#define BUFFSIZE 1024 // no. of FFT points (1024)
#pragma DATA_ALIGN(fft_buffer, 8)
float fft_buffer[2*BUFFSIZE]; // Length of input data (2048)
#pragma DATA_ALIGN(twiddles, 8)
float twiddles[BUFFSIZE]; // twiddles of FFT length (1024)
float fft_mag[BUFFSIZE];
short bitrev_table[BUFFSIZE]; // bitrev_table of FFT length (1024)
Following parts are already defined in dsk_app.c project as follows.
Int16 gBufferXmtPing[BUFFSIZE]; // Transmit PING buffer
Int16 gBufferXmtPong[BUFFSIZE]; // Transmit PONG buffer
Int16 gBufferRcvPing[BUFFSIZE]; // Receive PING buffer
Int16 gBufferRcvPong[BUFFSIZE]; // Receive PONG buffer
In main(), I generated coefficient table.
fft_r2_init(twiddles, BUFFSIZE, bitrev_table);
void fft_r2_init(float *w, int n, short *br_table)
{
int i;
gen_twiddle(w, n); // generate twiddle table of n/2 complex twiddles
//bit_rev(w, n/2); // put twiddle table in bit-reversed order
DSPF_sp_bitrev_cplx((double *)w, br_table, n/2);
for(i=0; i<n; i++) // initialize bit-rev table to zero
br_table[i] = 0;
bitrev_index(br_table, n);
}
-processBuffer() - I processed audio data with in this function once it received.
For PING Buffer
Here attached plot of gBufferRcvPing after getting 1024 samples of input. It looks fine to me.
http://i31.tinypic.com/35lcc2a.jpg
if (pingPong == PING) {
//The DSPf algorithms expect the real data in the even input buffer locations (2*k) and imaginary data in odd location (2*k+1)
for(k=0; k < 2*BUFFSIZE; k++)
{
fft_buffer[2*k] = (float)gBufferRcvPing[k]; //real
fft_buffer[2*k+1] = 0.0; //imag
}
Called FFT and bit reversed function.
fft_r2(fft_buffer, twiddles, BUFFSIZE, bitrev_table);
void fft_r2(float *x, float *w, int n, short *br_table)
{
DSPF_sp_cfftr2_dit(x, w, n); // in-place FFT
DSPF_sp_bitrev_cplx((double *)x, br_table, n);
}
Here attached plot of fft_buffer after FFT and bit reversal.
http://i31.tinypic.com/dq6cub.jpg
Then calculated FFT magnitude and copied it back to gBufferRcvPing buffer.
for(l=0; l < BUFFSIZE; l++)
{
fft_mag[l] = sqrt(fft_buffer[2*l]*fft_buffer[2*l] + fft_buffer[2*l+1]*fft_buffer[2*l+1]);
gBufferRcvPong[l] = (Int16)fft_mag[l];
}
/* Copy receive PING buffer to transmit PING buffer */
copyData(gBufferRcvPing,
gBufferXmtPing, BUFFSIZE);
void copyData(Int16 *inbuf, Int16 *outbuf, Int16 length)
{
Int16 i = 0;
for (i = 0; i < length; i++) {
outbuf[i] = inbuf[i];
}
}
Here attached plot of fft_mag after calculating magnitude of FFT transform.
http://i30.tinypic.com/15wntlg.jpg
I used the same approach for PONG Buffer.
Here attached plot of fft_buffer after FFT and bit reversal for PONG buffer.
http://i28.tinypic.com/acebv6.jpg
and here find the plot of fft_mag after calculating magnitude of FFT transform for PONG buffer.
http://i28.tinypic.com/2zemoo1.png
Moreoever, I am not sure how much is the sampling frequency, default one is 48Khz for dsk_app.c project, I changed the following parameter with in aic23.h file to make it 8Khz but I don't know wheather its working fine or not.
#define AIC23_DEFAULTPARAMS {
AIC23_REG8_8KHZ, }
Is this this the right way to change Sampling Rate ?
Where am I doing any thing wrong while calculating fft and magnitude ?
Why fft_mag doesn't show one clear peak for PING and PONG register ?
Is there any thing wrong with the length of twiddles, BUFFSIZE and fft_buffer ?
Please help me out.
Thanks.