cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 + DSP from STM32Cube_FW_F4_V1.7.0

yanvasilij
Associate II
Posted on August 20, 2015 at 06:42

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.

http://codepad.org/ogqLPpEd

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).

0690X000006058mQAA.png

What am I doing wrong?

Regards,

Vasilij
2 REPLIES 2
Posted on August 21, 2015 at 18:23

Hi yanikeev.vasilij,

May be you need to fill your input buffer correctly, you can dump the input buffer to verify it.

Insert this code:

for (i = 0; i < 1024*2; i += 2) 
{ 
input[(uint16_t)i] = (q15_t)uhADCxConvertedValue ; 
/* delete Imaginary part */ 
input[(uint16_t)(i + 1)] = 0; 
HAL_TIM_Base_DeInit(&htim1); 
} 

instead of:

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

This may resolve your issue. **** Please note that the output here is a full FFT (it is a mirror of the harmonics positives and negative ones). -Shahrzad-
yanvasilij
Associate II
Posted on August 24, 2015 at 06:24

shahrzad, Thank you very much! I did as you say and now it works!

 0690X000006031CQAQ.jpg