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.

F28027 - Toubles with a FFT

Hello,

I have some troubles with the FFT computation. I tried it with the TI fft library, but it didn´t work. When I´m activating the FFT the ADC reads only noise. But the windowing function and the FFT don´t work as well.

That´s my file:

#include "DSP2802x_Device.h"            // Peripheral address definitions
#include "Test.h"                    // Main include file
#include "fft.h"                        // FFT include file

#pragma DATA_SECTION(AdcBufA,"AdcBufFileA");
#pragma DATA_SECTION(AdcBufB,"AdcBufFileB");
#pragma DATA_SECTION(ipcb,"FFTipcb");
#pragma DATA_SECTION(mag,"FFTmag");

//--- Global Variables
Uint16 SpeedChanged = 1;
Uint16 AckAdc=0;
Uint16 AdcBufA[N];
Uint16 AdcBufB[N];
int32 ipcb[N+2];
int32 mag[N/2+1];

//--- Define FFT
RFFT32 fft=RFFT32_128P_DEFAULTS;

//--- Global Constants
const long win[N/2]=HAMMING1024;

/**********************************************************************
* Function: main()
*
* Description: Main function for C28x workshop labs
**********************************************************************/
void main(void)
{
.........

......

//--- FFT initialization
    fft.ipcbptr=ipcb;                    // FFT computation buffer
    fft.magptr=mag;                        // Store mag. square in separate buffer
    fft.winptr=(long *)win;                // Window coefficient array
    fft.init(&fft);                        // Twiddle factor pointer initialization


//--- Main Loop
    while(1)                            // endless loop - wait for an interrupt
    {
   

        if(AckAdc==1)
        {
//            RFFT32_brev((long *)AdcBufA,(long *)ipcb,N);    // geht ohne, ist wahrscheinlich in fft.init drin


//--- FFT Computation
            fft.win(&fft);                // Window the input data
            fft.calc(&fft);                // Perform 2Npoint complex FFT
            fft.split(&fft);            // Split function computation
            fft.mag(&fft);                // Obtain the magnitude square


            AckAdc=0;
    //        PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;        // Must acknowledge the PIE group

        }
    }


} //end of main()

Is there something wrong with the FFT declaration?

Maybe someone has a example file for me. Or is there another library with a FFT which I can use?

Thanks

Thomas

  • May be you should try with simple input(predefined) and check output to debug FFT by it self, and then go to experiments with ADC?

    Also, probably You should double check your code step by step..looking to fft lib documentation and examples.

    http://www.random-science-tools.com/maths/FFT.htm - was VERY useful for me.

     

    I can't get any detailed info, because i never used F28027 and corresponding fft lib.

    I think fft.init(&fft);  and fft.win(&fft);   looks strange(if FFT lib is coded in this way - then OK).  My FFT lib(for F28335) have dedicated finctions such as RFFT_f32u(&fft); to compute FFT for example....

     

  • Hey Vasily,

    thanks for the answer.

    I changed my program that i´m using the acquisiton module and then the fft module. The aquisition module works fine, but I have still some problem with the FFT module. I wrote my program like the examples fromt the ti fft library documentation. So should work.

    Does anyone have a working example for me? I tried the examples from TI but ther is the stb.h include file missing, so I can´t compile it.

    Thanks

    Thomas

  • As I understand RFFT32_128P_DEFAULTS; have to correspond with N? Is it Ok? And a can't see definition of N.

    And once again about Your problem. What exactly is wrong? ADC stops work correctly if you add FFT to the code? Can You first  debug FFT only(i.e. without windowing, without phase, ADC, etc..) And only after FFT will be OK - we can talk about why ADC can stop working correctly. Ok?  I don't believe that TI can release not working FFT lib [:)] so problem is on Your side.

    Can you provide URL to this FFT lib? I can't find it yet...

    P.S. oops, I push the Suggest answer button. Sorry, ofcourse there is no answer in this post. I did it casually.

  • Yes I found some mistakes in my file and i defined my N in an include file.

    I will try to debug my program now to find exactly the mistake where my program stops working correctly.

    Here you can find the fft library: http://focus.ti.com/docs/toolsw/folders/print/sprc081.html

  • Thanks for all my FFT is working now.

    Thomas

  • Hey Tom,

    I believe I am working on a similar project as you. I am trying to read an input off of the ADC and perform an FFT on the data.  I am also having some trouble with the FFT library.When I enter this line of code "RFFT32 fft=RFFT32_128P_DEFAULTS;", it wont compile and says the symbols "CFFT32_calc, CFFT32_init, RFFT32_mag, RFFT32_split, RFFT32_win" are undefined.

    Here is my code, it looks pretty similar to yours as I have just been going from the example code given in the document that came with the library.  I'm not sure if I'm even going about this in the right manner, and haven't been able to debug at all because the compiler stops after the RFFT32 fft=RFFT32_128P_DEFAULTS line.

     

    #include "PeripheralHeaderIncludes.h"
    #include "DSP280x_EPwm_defines.h"         // useful defines for initialization
    #include "fft.h"   


    int i;
    #define N 128;
    unsigned short inputsig[128];

    #pragma DATA_SECTION(ipcb,"FFTipcb");
    #pragma DATA_SECTION(mag,"FFTmag");

    RFFT32 fft;
    RFFT32 fft=RFFT32_128P_DEFAULTS;

    void init(RFFT32_handle);
    void calc(RFFT32_handle);
    void split(RFFT32_handle);
    void mag(RFFT32_handle);
    void win(RFFT32_handle);

       
    long ipcb[128+2];
    long mag[128/2+1];
    const long win[128/2]=HAMMING128;

     

    void main(void)
    {

    .......

    .......
        fft.ipcbptr=ipcb; // FFT computation buffer
        fft.magptr=mag; /* Store mag. square in separate buff*/
        fft.winptr=(long *)win; /* Window coefficient array */
        fft.init(&fft); /* Twiddle factor pointer initialization */
      
    //=================================
    //    Forever LOOP
    //=================================

        for(;;)  //infinite loop
        {
                // reads the values from adc into inputsig[128] <-this is what I am looking to take the FFT of
            for(i=0; i<128; i++){
           
                adc_result = AdcResult.ADCRESULT0;
                inputsig[i]= adc_result;        // Store ADC measurement to adc_result buffer
               
            }   
                                            // level of the PWM1A_DAC output (the value

       
        fft.win(&fft); /* Window data*/
        fft.calc(&fft); /* Perform FFT*/
        fft.split(&fft); /* Split function computation*/
        fft.mag(&fft); /* Obtain the magnitude square*/
                                           
        }                                               

        
    }

    Any help you can give would be greatly appreciated.

    Thanks,

    Matt

  • Hey Matt,

    try it like this and it will work. The most is the same than in the TI example. Did you download ist?

    #include "fft.h"                            // FFT include file
    #pragma DATA_SECTION(ipcb,"FFTipcb");

    //--- Create an instance of RFFT module
    RFFT32 fft=RFFT32_1024P_DEFAULTS;            // Instance the FFT module

    //--- FFT initialization
        fft.ipcbptr=ipcb;                            // FFT computation buffer
        fft.magptr=ipcb;                            // Store mag. square in separate buffer
        fft.winptr=(long *)win;                 // Window coefficient array
        fft.init(&fft);                                     // Twiddle factor pointer initialization

    //--- Perform the FFT
        RFFT32_brev(ipcb,ipcb,N);            // resort the ipcb to N/2-point complex data sequence in bit-reversed order
        fft.win(&fft);                         // Window the input data
        fft.calc(&fft);                        // Perform N/2 complex FFT
        fft.split(&fft);                        // Split function computation to obtain the computation of a real FFT
        fft.mag(&fft);                       // Obtain the magnitude square

    Now you have the result in your ipcb. I performed the calculation of the fft and the magnitude in the ipcb.

    Best regards

    Tom

  • Hey Tom,

    Thank you for the very quick response. It helped me take care of some of the errors I was getting. I'm sorry to bug you again, but I am a bit of a novice when it comes to programming.  I think the way I am reading from the ADC is causing errors.I am creating an array, and reading in 128 values from the ADC (to which I am currently feeding a simple 1Khz sine wave) like this,

    for(i=0; i<128; i++){
           
                adc_result = AdcResult.ADCRESULT0;
                inputsig[i]= adc_result;        // Store ADC measurement to adc_result buffer
               
            }   

    I then tried

    RFFT32_brev(inputsig,ipcb,N);

    which I thought would take the 128 values of 'inputsig' as the source and 'ipcb' as the destination, but I am just getting random numbers popping up on the ipcb variable in the watch window.

    Is this similar to how you acquired your data from the ADC? I have tried using the RFFT32_ACQ function instead of the RFFT32_brev, but it was giving me some errors.

     

    Again, thank you very much,

    Matt