cancel
Showing results for 
Search instead for 
Did you mean: 

FFT Problem in Loop STM32F4-Disco

Tarkan Dalay
Associate
Posted on June 24, 2017 at 11:09

Hi folks;

I want to use fft (1024) in my signal which came from i2s, so it's should be real time. I'm new at fft, there may be some mistakes. And sorry for my bad english

When i use fft without loop everything works fine;

void main(){
.....
arm_cfft_f32(&CFFT_LENGTH,wave_buffer,ifft_Flag,doBitReverse);
arm_cmplx_mag_f32(wave_buffer,fft_Output,fft_Size);
arm_max_f32(fft_Output,fft_Size,&MaxValue,&testIndex);�?�?�?
....
 while(1){
 
 ....
 }
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

But in loop, ihave a trouble, as in the picture;

*memcpy for refresh buffer or new data inputs

void main(){
.....
....
 while(1){
 memcpy(&wave_buffer,&wave_Input,2048);
 arm_cfft_f32(&CFFT_LENGTH,wave_buffer,ifft_Flag,doBitReverse);
 arm_cmplx_mag_f32(wave_buffer,fft_Output,fft_Size);
 arm_max_f32(fft_Output,fft_Size,&MaxValue,&testIndex);�?�?�?
 
 ....
 }
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

0690X00000607RsQAI.png

I solved this problem but i had new one. First value isright, others isn't.

void main(){
.....
 memcpy(&wave_buffer,&wave_Input,2048);
 arm_cfft_f32(&CFFT_LENGTH,wave_buffer,ifft_Flag,doBitReverse);
 while(1){
 counter++; 
 if(counter%2==0){
 memcpy(&wave_buffer,&wave_Input,SAMPLES);
 max_freq=(48800/1024)*testIndex;
 arm_cmplx_mag_f32(wave_buffer,fft_Output,fft_Size); 
 arm_max_f32(fft_Output,fft_Size,&MaxValue,&testIndex);
 }
 else{
 memcpy(&wave_buffer,&wave_3_440Hz_44100,SAMPLES);
 max_freq=(44100/1024)*testIndex;
 arm_cmplx_mag_f32(wave_buffer,fft_Output,fft_Size); 
 arm_max_f32(fft_Output,fft_Size,&MaxValue,&testIndex);
 } 
 
 .....
 }
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

0690X00000607UWQAY.png

Question-1: Why

frequency

valueschanged unexpectedly? (terminal picture-1)

Question-2: Why frequency values isn't equals reference values? (terminal picture-2)

Board:STM32F4-Discovery

*I used the calculations on this link;

http://support.ircam.fr/docs/AudioSculpt/3.0/co/FFT%20Size.html

*review CMSIS DSP_Lib/Examples

*some codes written with ''arm_status arm_cfft_radix4_init_f32''

I read this ''Do not use this function. It has been superceded by arm_cfft_f32 and will be removed in the future.''

in CMSIS-DSP_Lib 1.4.7, so i didn't use radix4 functions.

Best Regards.

#armcm4.h-arm_math.h #fft
6 REPLIES 6
mohit rai
Associate II
Posted on January 16, 2018 at 10:38

Hello,

I am also using same procedure for FFT. I am using ADC values for FFT input but I am not getting random value of frequency. I am reading ADC value using DMA at sampling rate of 8000 hertz.

how can I solve this problem?

Thanks in advance.

Regards,

Mohit rai

Posted on January 16, 2018 at 17:29

Hi

rai.mohit

‌,

Try to use the FFT example available in

http://www.st.com/en/embedded-software/x-cube-dspdemo.html

. It runs on STM32F429I-DISCO & STM32F746-DISCO.

You can refer to AN4841 to get more idea about the usage of this package besides to the expected results.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 16, 2018 at 18:48

>>how can I solve this problem?

Start by understanding the source of the problem.

Make test cases using data sets you can test on the STM32 platform and on a PC platform.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 16, 2018 at 19:02

Thank you for reply. 

Posted on January 16, 2018 at 19:17

Hello,

Thank you for your response. I have generated 500 Hertz sin wave(with DC offset 2047 or without DC offset ) in matlab and perform the fft on the same data.when DC offset shift data is used for FFT, my index is 0 . And for without DC shift DC data, my index is right.

Is DC shift affecting my FFT calculation?

I have tried same procedure  with ADC data (ADC data is microphone value).  index is changing randomly.

Thanks

Regard,

Mohit Rai

Posted on January 16, 2018 at 20:07

My concern with ADC+DMA acquired samples is that the data buffers can change during the execution time of the function. You should test and validate static data sets with the ARM routines, I believe DSP library routines are provided in source form.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..