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.

LAUNCHXL-F28379D: Understanding Fixed Point RFFT

Part Number: LAUNCHXL-F28379D
Other Parts Discussed in Thread: C2000WARE

Hi, 

I am trying to use RFFT for analog data on F28379D-LAUNCHXL. Before that I have constructed the below signal in  MATLAB at the frequency of 3.2 ksps

than converted the decimal values to the Q31 format using some scaling factor M > Max of signal (let 1300 > 1290) and 2^31, such as final scaling factor as 2^31/1300 = 16,51,910.

        //input signal
        for(i=0; i < FFT_SIZE; i++){
          ipcbsrc[i]  = (long)  1651910* result[i];  //Q31  // Range of the input - 0-1299 (0-1V) => to bring into range of 0-1 divide by 1300 and then to get Q31 format multiply with 2^31 = (approx.) 1651910
        }

After performing the the 64 point RFFT  - 

 

  RFFT32_brev(ipcbsrc, ipcb, FFT_SIZE); // real FFT bit reversing

        rfft.ipcbptr = ipcb;                  // FFT computation buffer
        rfft.magptr  = ipcbsrc;               // Magnitude output buffer

        rfft.winptr  = (long *)win;           // Window coefficient array
        rfft.init(&rfft);                     // Twiddle factor pointer initialization

        rfft.calc(&rfft);                     // Compute the FFT
        rfft.split(&rfft);                    // Post processing to get the correct spectrum
        rfft.mag(&rfft);                      // Q31 format (abs(ipcbsrc)/2^16).^2

Below is the output on ipcbsrc-

As per Fixed Point document  - 

But I don't see same on the ipcbsrc. 

Also, when I am trying to get back the magnitude in the decimal format below is the output for different frequency components - 

Q31 Decimal(output of FFT) Decimal(Actual) Input
Dc 264680099 160.2267067 645.430303
Fundamental ( 50Hz) 61190090 37.04202408 620.6060606
100Hz 2450431 1.483392558 124.1212121
150Hz 152972 0.092603108 31.03030303
200Hz 0 0 0
250Hz 24725 0.014967522 12.41212121

decimal output is derived from Q31 output by dividing with initial factor (1651910) used to convert the decimal value to Q31 format.

Can you help me understand why output decimal values are not same as the input decimal inputs.,

Thanks & Regards,

Kuldeep

 

  • Can anyone please help with this ? 

  • Hi,

    Please give me a couple of days to look into this and revert back.

    -Shantanu

  • HI Shantanu,

    Thanks for your reply. Please try to help as earliest possible. 

    Thank you.

    -Kuldeep

  • Hi,

    Anyone can help with this ?

    Thank you.

    -Kuldeep

  • Hi Shantanu and Others,

    Can anyone help with this?

    Thank you.

    -kuldeep

  • Hi,

    I am unable to replicate your problem. I ran with both N = 64 and 256. Please verify the hamming window and RFFt parameters that you are using. Also try to increase the value of N to see if the problem goes away. 

    -Shantanu

  • Hi Shantanu,

    I have the code as below - 

    1. Declaration

    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include <time.h>
    #include <stdlib.h>
    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include <stddef.h>
    #include "fft.h"
    #include "fft_hamming_Q31.h"
    #include "math.h"
    
    //
    // Defines
    //
    #define FFT_SIZE            64
    #define q31convfactor       1651910   // Range of the input - 0-1299 (0-1V) => to bring into range of 0-1 divide by 1300 and then to get Q31 format multiply with 2^31 = (approx.) 1651910
    
    //
    // Globals
    //
    
    // Create the FFT buffers, ipcb and ipcbsrc, in sections with the same name
    #ifndef __cplusplus
    #pragma DATA_SECTION(ipcb, "FFTipcb");
    #else
    #pragma DATA_SECTION("FFTipcb");
    #endif
    int32_t ipcb[FFT_SIZE+2];
    
    #ifndef __cplusplus
    #pragma DATA_SECTION(ipcbsrc, "FFTipcbsrc");
    #else
    #pragma DATA_SECTION("FFTipcbsrc");
    #endif
    int32_t ipcbsrc[FFT_SIZE];
    
    // Declare and initialize the structure object.
    // Use the RFFT32_<n>P_DEFUALTS in the FFT header file if
    // unsure as to what values to program the object with.
    RFFT32  rfft = RFFT32_64P_DEFAULTS;
    
    // Define window Co-efficient Array
    // Note: Windowing is not used in this example
    const long win[FFT_SIZE/2]=HAMMING64;
    
    int16_t test_input[FFT_SIZE] = {645,745,842,931,1011,1080,1138,1185,1222,1250,1270,1283,1290,1290,1283,1269,1247,1220,1188,1152,1114,1077,1041,1006,973,941,908,874,835,793,747,697,645,594,544,498,456,417,382,350,318,285,250,214,176,139,103,71,43,22,8,1,1,8,21,41,69,106,153,211,280,360,449,546};
    
     

    2. execution code -

    //Initialization 
         //Clean up input/output buffer
         for(i=0; i < (FFT_SIZE+2); i=i+2){
           ipcb[i]   = 0;
           ipcb[i+1] = 0;
         }
    
    
    
    //In While Loop
           //input signal
           for(i=0; i < FFT_SIZE; i++){
              ipcbsrc[i]  = (long)  q31convfactor*test_input[i];  //Q31
           }
    
            RFFT32_brev(ipcbsrc, ipcb, FFT_SIZE); // real FFT bit reversing
    
            rfft.ipcbptr = ipcb;                  // FFT computation buffer
            rfft.magptr  = ipcbsrc;               // Magnitude output buffer
    
            rfft.winptr  = (long *)win;           // Window coefficient array
            rfft.init(&rfft);                     // Twiddle factor pointer initialization
    
            rfft.calc(&rfft);                     // Compute the FFT
            rfft.split(&rfft);                    // Post processing to get the correct spectrum
            rfft.mag(&rfft);                      // Q31 format (abs(ipcbsrc)/2^16).^2

    Please have a look and let me know if I am doing something wrong in this?

  • Hi,

    This looks correct. Have you aligned ipcb correctly in the linker cmd file? Also, can you run the stock examples in c2000ware and compare the input and output in your matlab model? We also provide a matlab script in c2000ware to help you verify. This is just to isolate the issue.

    -Shantanu

  • Hi Shantanu,

    Thank you for your input.

    As per document the magnitude output is in the form of Q30 format but in the example code they have mentioned Q31 as below - 

    After checking the document and scaling the values as per Q30 we are able to get the correct dc component but th fundamental and other harmonic components require a multiplication of a factor 2.

    where q30convfactor is 1073741824 and adcrefconv is 1volt 

    can you help with this if its due to RMS value or some other thing ? 

    Thank you.

    -Kuldeep