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.

TMS320F2808: Fixed Point DSP Software Library

Part Number: TMS320F2808


Hi,

I am currently completing a project that uses the TMS320F2808 processor to acquire two channels of data using 16-bit ADCs which is then processed using the Fixed Point DSP software library in order to determine frequency content from D.C. to about 5KHz

My setup is essentially working but I do not quite get the responses that I would have expected when using a test square wave. The test square wave has a frequency of 100.6Hz at its peak-to-peak magnitude is set to 0x7FFF0000 (approx. +1) to 0x80010000 (approx. -1) in Q31 format.

I am sampling at a frequency of 12877Hz and collect 1024 samples which are processed using an instance of rfft to generate real magnitude data.

The first four Q30 results is am getting are as follows.

bin   magnitude

8      0x19F11CF9

24    0x02E31686

40   0x010AEDAF

56   0x0088D8CC

To get floating-point values, I then divide each Q30 result by 2^30 then multiply by 2. Leaving the values in RMS^2 form as follows.

8      0.810682714

24    0.0902206972

40    0.0325840376

56    0.0167049393

Taking the square root of each value produces the final result.

8      0.9

24    0.3

40    0.1895

56    0.1292

Since the input square wave has a maximum amplitude of approx. +/-1 I would have expected the magnitudes to have been 1, 1/3, 1/5 and 1/7.

If I change the input signal to a D.C. level of 0x7FFF0000 throughout, get a value in bin 0 of 0x3FFF0001 which when divided by 2^30 and then square rooted gives a value of 0.9999 as expected. There is no multiply by 2 for bin 0 as far as I can figure.

This is how I am interpreting the Q31 results, which may be where the problem lies somewhere.

For all bins I divide by 2^30 to get a floating-point value. Then for all bins except bin 0 I multiply this by 2. Then for all bins I find the square root to yield the final answer.

Would this be correct?

Should I be able to expect results that are more accurate than this?

Regards

FarmerJo

  • Farmer,

    Thank you for your inquiry. Please be patient with us as we try to find the right person to handle this question.

    Regards,

    Richard
  • Hi, 

    the RFFT32_Mag should give you the magnitude squared in Q30 format.

    So ,

    hex2dec('19F11CF9')/2^30 = 0.4053

    sqrt(hex2dec('19F11CF9')/2^30) = 0.6367

    I modified the MATLAB script that comes in the RFFT example folder to accept a square wave with frequency 100.6Hz as input. I took into account your sampling rate when generating the input samples to the FFT.

    MATLABs in-built FFT is run on the input at line 77

        fft_float=2^31*fft(x/2)/N;

    You can check the 8th bin (index 9 for MATLAB) 

      (abs(fft_float(9))/2^30)^2 = 0.4053

       abs(fft_float(9))/2^30 = 0.6366

    If you continue to execute you will run the custom algorithm that the embedded target uses

       Magnitude_Fixed(9)/2^30 = 0.4053

      sqrt(Magnitude_Fixed(9)/2^30) = 0.6366

    The results match. It looks like the input is halved prior to running the fft.

    I had to do some digging on this, since ive forgotten how to derive it, but the fourier series of a square wave is 

    F(x) = 4/pi * (sin(x) - 1/3*sin(3x) + 1/5*sin(5x) - ...)

    and since we compute the fourier on half the input, the magnitude of the fundamental frequency (bin 8) is 2/pi or 0.6366. If you run the fft on the input without halving you should see 4/pi, but we halve the input on the embedded target to prevent overflow

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/171/FixedRFFTnoWin_5F00_modified.m

  • Many thanks for the super answer!

    Yes it I had no taken into consideration the 4/pi term in the Fourier series.

    It all works as expected, thanks for your time and effort in to answering this question,, it is much appreciated.

    Many Regards

    FarmerJo