AnsweredAssumed Answered

STM32F407 + DSP from STM32Cube_FW_F4_V1.7.0

Question asked by yanikeev.vasilij on Aug 20, 2015
Latest reply on Aug 24, 2015 by yanikeev.vasilij
Hello! 

I trying to create an aplication with FFT. So, I read 1024 points from internal ADC (12 bit), sampling frequency 1024 Hz. Then I process them with FFT functions from DSP lib STM32Cube_FW_F4_V1.7.0.

Here my code

arm_cfft_radix2_instance_q15 fftInstance;

static u32 curInputCursor=0;

static u32 dataIsReady = 0;

static q15_t input [2048]; /**< input points */

static q15_t output [1024]; /**< output frequencycharacteristic */

 

/** @brief Timer interrupthandler. Frequncy = 1024 Гц */

extern "C" void timerInterrupt (void)

{

        input[curInputCursor++]=uhADCxConvertedValue;/**< making 1024 points from ADC DMA */

        if (curInputCursor>=1024)

        {

               curInputCursor= 0;

               dataIsReady= 1;

               HAL_TIM_Base_DeInit(&htim1);/**< turn off interrupts when all data is ready */

        }

        invertLed(); /**< Checking sampling frequency on osciloscope (1024 Hz it's true) */

}

 

/** @brief Task with FFTcalculation */

static void fftTask (void *p)

{

        q15_t maxValue;                       /* Max FFT value is stored here */

        uint32_t maxIndex;                            /* Index in Output array where max value is */

 

        while(1)

        {

               if (dataIsReady) /**< if datais ready starting calculation */

               {

                       dataIsReady= 0;

 

                       arm_cfft_radix2_init_q15(&fftInstance, 1024, 0, 1);

                       arm_cfft_radix2_q15(&fftInstance,input);

                       arm_cmplx_mag_q15(input, output, 1024);

                       u32index;

                       saveFft();

                       timInit();/**< run timer again for next 1024 points */

               }

        }

}

 



I expect in output[] frequency characteristic with 1 Hz step. output[0] is constant signal, output[1] - first harmonic, output[2] - second and etc. But when I connect 50 Hz 1 V ampl and  constant with 1V, I have the follow: output[0] = 0; output[1] = 543; output[3] = 181; output[50] = 181 (picture bellow).

output.png

What am I doing wrong?

Regards,
Vasilij

Outcomes