Project

General

Profile

Calculating FFT using SigProcTIDspSupport in SigProc library

Added by Rafał Krawczyk over 10 years ago

Hello,
I am trying to compute the FFT from 2 signals at once. So far I managed to compute the FFTs of my signals basing on the SigProcFFT.cpp file with the commented example. However, for efficienty purposes(I am dealing with real-time system and computation time of FFT is critical in my project), I would like to compute the FFT using the Efficient Computation of the DFT of Two Real Sequences, just like it is done in commented example in SigProcTIDspSupport.cpp. As a test, I was trying to compute the FFT for tho sine signals, defined in the following lines of code:

//signals eclarations
static float sin21[2048];
static float sin42[2048];
float omega21 = 2.0*( 3.14159265358979323)/64;
float omega42 = 2.0*omega21;
for(int i = 0; i < 2048; i++) {
sin21[i] = sin(omega21*i);
sin42[i] = sin(omega42*i);
}

Subsequently, I implemented the FFT computation basing on the example code in SigProcTIDspSupport.cpp, except I did not want to use the Hanning window and I already had float-type signals, so I ommited the convervion to float and the multiplication of signal. The computation in my code looked like this:

float* mpTwiddles    = new float[FFT_SIZE*2+8];   // TI FFT twiddle factors
float* mpWorkBuff = new float[FFT_SIZE*2+8]; // working buffer
float* mpFFTA = new float[FFT_SIZE*2]; // FFT output for A
float* mpFFTB = new float[FFT_SIZE*2]; // FFT output for B
short* mpBitReverseIndex = new short[tcSigProcTIDspSupport::bitrev_index_length(FFT_SIZE)];
//allignment of data structures for twiddle factor and working buffer
if ((unsigned int)mpTwiddles & 7) {
mpTwiddles = (float*)(((unsigned int)mpTwiddles+8)&~7);
}
if ((unsigned int)mpWorkBuff & 7)
{
mpWorkBuff = (float*)(((unsigned int)mpWorkBuff+8)&~7);
}
// I am not quite sure about second parameter of the following method- In the example there was the LOW_RES_FFT_SIZE parameter, but I did not find its definition
//so I set the value to the size of mpBitReverseIndex array
tcSigProcTIDspSupport::compute_bitrev_index(mpBitReverseIndex, tcSigProcTIDspSupport::bitrev_index_length(FFT_SIZE));
// Generating the twiddle factors
tcSigProcTIDspSupport::gen_w_r2(mpTwiddles,FFT_SIZE);
tcSigProcTIDspSupport::bit_rev(mpTwiddles,FFT_SIZE>>1);
// move the signals into working buffer- data signals are put in odd and even indexes of working buffer
for(int i=0;i!=FFT_SIZE;i+=2) {
mpWorkBuff[i]=sin21[i];
mpWorkBuff[i+1]=sin42[i];
}
// do the TI FFT
DSPF_sp_cfftr2_dit(mpWorkBuff,mpTwiddles,FFT_SIZE);
// fix the output order to be sorted normally
DSPF_sp_bitrev_cplx((double*)mpWorkBuff, mpBitReverseIndex, FFT_SIZE);
// extract the two sets of data
tcSigProcTIDspSupport::ExtractDualRealFFT(mpWorkBuff, mpFFTA, mpFFTB,
FFT_SIZE, FFT_SIZE);

I anticipated to get as a results the FFT spectra in mpFFTA and mpFFTB with single positive "spike" (one value in output array much larger than others- quite visible if you view the array as an expression in Debug perspective in CCSv5 and then right-click view it as a graph), just like it was when I implemented the transform using the SigProcFFT.cpp example. However, the resulting spectra were incorrect. Do you know, what could be the reason for this ?If you have any suggestions, any help is invariably welcome.
Thank you in advance
Rafal Krawczyk


Replies (2)

RE: Calculating FFT using SigProcTIDspSupport in SigProc library - Added by David Rice over 10 years ago

I think your problem is here:

for(int i=0;i!=FFT_SIZE;i+=2) {
mpWorkBuff[i]=sin21[i];
mpWorkBuff[i+1]=sin42[i];
}

Your indices for the two sin waves are incrementing by two, while they should be incremented by one.

Try this:

for(int i=0;i<FFT_SIZE;i++) {
mpWorkBuff[2*i]=sin21[i];
mpWorkBuff[2*i+1]=sin42[i];
}

That may not be the only problem, but it certainly is part of the problem. Let me know if that helps.

Dave

RE: Calculating FFT using SigProcTIDspSupport in SigProc library - Added by Rafał Krawczyk over 10 years ago

Hello,
It was the cause-thank you very much.It works. Curious enough, I now realised that the corrected implementation of SigProcTIDspSupport example works well now, whereas my SigProcFFT implementation returns the spikes with incorrect sign. In my implementation of SigProcFFT example I invoked the following methods (for the same sin21 array as in SigProcTIDspSupport):

SetupFFT(1024);
ComputeFFT(sin21);

Where SetupFFT was the following:

void SetupFFT(int fftsize) {
float *workbuffer;
workbuffer = new float[4*MAX_DSP_FFT_SIZE];
pcRealFFT = new tcRealFFT(workbuffer, fftsize*sizeof(float), fftsize);
}

And the ComputeFFT was the following (currently I am not using the Hanning Window):

void ComputeFFT(float *inputdata) 
{
pcRealFFT->Compute(inputdata);
}

I anticipated to get the negative spike for sine wave spectrum, but it was positive instead. If you know where the mistake is, I am all ears.

Best Regards
Rafal Krawczyk

    (1-2/2)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)