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.

MSP430FR5994: FFT calculation using LEA

Part Number: MSP430FR5994

Hi,

I have a customer who is evaluating LEA in MSP430FR5994.
He is using acceleration data (x, y, z) as input and calculate FFT using LEA.
These input values are between -40 to +40 [m/s^2].

Now I got below questions:
Q1) According to DSPLib API guide, only Q15 and IQ31 formats can be used as fixed-point type.
So all input values need to be normalized within -1 and +1 and converted to Q15 or IQ31 format before LEA operation, correct ?

Q2) What is maximum FFT length supported by LEA? 4096 can be used ?

Q3) Suppose FFT length is 256 with 50Hz sampling rate, we get 256 output data.
Q3-1) How does 256 data corresponds to frequency ?
Q3-2) According to DSPLib API guide, output value is divided by 128 in case msp_fft_fixed_q15() is used.
(I guess the reason is to avoid overflow)
Is it OK to multiply the results by 128 to get original values ?

Q4) The output value includes negative values as well as positive values.
Usually FFT results are only positive values for example when CCS “FFT Magnitude Graph” is used.
Is there any option to get such positive values ?

Thanks and regards,
KoT

  • Hi KoT,

    1. Q15 and IQ31 are the precision of the FFT functions and operate on 16-bit and 32-bit inputs respectively. The input to the FFT can be any integer or fixed point type and the result will be the same format, if the input to the FFT is an array of integers the result will also be integers.
    2. The maximum FFT length supported by LEA is constrained by the available RAM and alignment requirements. MSP430FR5994 has 4KB of shared RAM however some of that is allocated for the LEA stack so the maximum FFT size is 1024 points (2048 bytes for Q15). If there is a future device with more shared RAM a larger FFT size is possible however at the moment 1024 is the largest possible FFT size using LEA.
    3. The result of the FFT is an array of complex pairs, a 256-point real FFT will have 128 complex pair results. The frequency resolution of each result is the sample frequency divided by size so in your case each result corresponds to 0.1953125 Hz (50 Hz / 256). Because the real FFT only calculates the first half of the frequency domain the results will range from 0 Hz (index 0) to 24.8046875 Hz (index 127).
    4. The result are scaled to prevent overflow, its not necessary to scale unless you want to compute the true FFT result.
    5. As indicated in #3 above each result is actually a complex pair. The complex pair can be used to compute both the magnitude and phase, the magnitude is simply sqrt(real^2 + imag^2) and the phase is arctan(imag, real). You will need to do this step after the FFT if you are looking to get the same result as the CCS FFT calculation.

    Hopefully the above answers your questions, it might also help to research more on Fourier transforms to get a better understanding of what they are and what the results mean

    Regards,

    Brent Peterson

  • Hi Brent,

    Thanks for your detailed answers!
    I was able to get FFT results and compare them with results calculated by Excel FFT.
    Please see attached excel sheet for summary.

    FFT with LEA_iq31.xlsx

    In “Data to Hex” sheet, data surrounded by red lines are used as LEA input array.
    In “LEA_X_FFT”, “LEA_Y_FFT” and “LEA_Z_FFT” sheets, data surrounded by red lines are output data by LEA.
    I calculated magnitudes and compared them with FFT results calculated by Excel data analysis (“FFT by Excel” sheet).

    As you can see, frequency characteristics are the same for both LEA and Excel results.
    But magnitudes absolute value are much higher in LEA results.
    Do you know why such differences happen ?

    Thanks and regards,
    KoT

  • Different FFT's have different scaling.
  • KoT,

    More specifically the magnitude of the LEA result in your excel sheet is exactly twice the excel reference FFT result.

    As Keith pointed out different FFT implementations have different scaling. In this case the result is scaled by two because you are using the optimized real FFT function which only calculates the first half of the transform (the second half is the complex conjugate of the first half mirrored around N/2). The easiest way to think about it is that components in the second half of the spectrum are included in the first half such that the total power of the real FFT is equal to the power of the complex FFT. The real FFT algorithm is explained in more detail in the comment block of the msp_split_iq31 function and references this app note: www.ti.com/.../spra291.pdf

    If you modify your code to use the complex FFT function (msp_cmplx_fft_iq31) you should get a result that closely matches the excel results. The complex FFT functions on average take twice as long so it's not recommended to use them when the input data is all real but you can use them to compare results.

    Regards,

    Brent

  • Hi Brent,

    Thanks for detailed answer.
    I understood real FFT results are twice compared to reference FFT calculation.

    I found msp_fft_fixed_q15() gives different results as msp_fft_iq31().
    msp_fft_fixed_q15() results are exactly same as reference FFT calculation done by excel.
    Please see attachment.

    To put input data within int16 scale, they are divided by 3 (for Y values) or 15(for Z values).
    So results are multiplied by 3(for Y) or 15(for Z).
    Then all X, Y, Z are multiplied by 128, because msp_fft_fixed_q15() applies scaling factor of 1/128.
    FFT with LEA_q15.xlsx
    I thought both msp_fft_iq31() and msp_fft_fixed_q15() use the same real FFT algorithm except;
    - input data format (16 or 32 bits)
    - scaling (with or without scaling)
    Do you know why they show different scaling results ?

    Thanks and regards,
    KoT

**Attention** This is a public forum