This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FFT result interpretation

I need to sample through codec, compute 64 point FFT and detect car horn frequency from the FFT results for my application. I am using the audio_filter demo for USB stick. I have modified the FFT_Filter() function as I do not need convolution/IFFT, but only FFT.  The function is like this now.

void FFT_Filter(Int32 *In, Int32 *Out)
{
    Int32 *data_br;
    Uint16 fft_flag, scale_flag;

    data_br = data_br_buf;

    // FFT Input Samples:
    fft_flag = FFT_FLAG;
    scale_flag = SCALE_FLAG;

    hwafft_br(In, data_br, FFT_LENGTH);  // bit-reverse input data
    (*Hwafft_Func) (&data_br[0], Out, fft_flag, scale_flag); // perform FFT
}

In main() I call

FFT_Filter(&FilterIn[0], &FilterOut[0]);

Now if I want to print the FFT result or compare the FFT result with say MATLAB FFT result for the same .wav file. What should I do?

What I understand is MSB 16 bits of FilterOut[] contains the real part of the result. So I need to do FilterOut[0] >> 16.
Now for S16Q15, I read it is 16 bits with 15 bits denoting fractional part after decimal point.  So will
(FilterOut[0] >> 16) && 0x8000 give me the sign of the result?

And how should I print the fractional part for correct interpretation?  (Int16)((FilterOut[0] >> 16) && 0x7FFF) will give me some value between 0 and 32767. How will I map that to FFT result which is said to range between  -1 and 0.9999 (in the release ) note that came with the audio filter demo?

Will MATLAB reult also be between -1 and .9999? Or I have to normalize or do something else?


Please help me to correctly interpret the ezdsp FFT results.

Thanks in advance,

Riju

  • Prior to buying the ezdsp, I did this car horn detection from audio recorded from road on my PC. I used an open source implementation of FFT by Dominic Mazzoni that had the FFT function as follows. I read .wav file using libsndfile API function sf_readf_float(SNDFILE *sndfile, float *In, sf_count_t frames) and called the following power spectrum function on In, an array of float.

    void PowerSpectrum(int NumSamples, float *In, float *Out)
    {
       int Half = NumSamples / 2;
       int i;

       float theta =  3.14159265358979323846/ Half;

       float *tmpReal = new float[Half];
       float *tmpImag = new float[Half];
       float *RealOut = new float[Half];
       float *ImagOut = new float[Half];

       for (i = 0; i < Half; i++) {
          tmpReal[i] = In[2 * i];
          tmpImag[i] = In[2 * i + 1];
       }

       FFT(Half, 0, tmpReal, tmpImag, RealOut, ImagOut);

       float wtemp = float (sin(0.5 * theta));

       float wpr = -2.0 * wtemp * wtemp;
       float wpi = float (sin(theta));
       float wr = 1.0 + wpr;
       float wi = wpi;

       int i3;

       float h1r, h1i, h2r, h2i, rt, it;

       for (i = 1; i < Half / 2; i++) {

          i3 = Half - i;

          h1r = 0.5 * (RealOut[i] + RealOut[i3]);
          h1i = 0.5 * (ImagOut[i] - ImagOut[i3]);
          h2r = 0.5 * (ImagOut[i] + ImagOut[i3]);
          h2i = -0.5 * (RealOut[i] - RealOut[i3]);

          rt = h1r + wr * h2r - wi * h2i;
          it = h1i + wr * h2i + wi * h2r;

          Out[i] = rt * rt + it * it;

          rt = h1r - wr * h2r + wi * h2i;
          it = -h1i + wr * h2i + wi * h2r;

          Out[i3] = rt * rt + it * it;

          wr = (wtemp = wr) * wpr - wi * wpi + wr;
          wi = wi * wpr + wtemp * wpi + wi;
       }

       rt = (h1r = RealOut[0]) + ImagOut[0];
       it = h1r - ImagOut[0];
       Out[0] = rt * rt + it * it;

       rt = RealOut[Half / 2];
       it = ImagOut[Half / 2];
       Out[Half / 2] = rt * rt + it * it;

       delete[]tmpReal;
       delete[]tmpImag;
       delete[]RealOut;
       delete[]ImagOut;
    }

    I am from CSE background and have only basic idea of DFT. Can somebody tell whether this FFT computation is same/different from the fft computation in the audio filter demo? In audio filter demo, the imaginary part is made 0, as I can understand from the code. But here both real and imaginary part are being used, they are squared and added to get power at the end.  How does the FFT results of audio-filter demo compare to that ? My processing of the FFT results will depend on that.

    Please let me know if anyone can help me out.

    Thanks in advance,

    Riju