cancel
Showing results for 
Search instead for 
Did you mean: 

FFT in STM32F7 MCU

Edwin kaus
Associate II
Posted on February 21, 2018 at 13:26

Hello.,

I need to write test code for Audio codec which is interfaced through SAI interface . For this I am generating 1KHz sine wave using DAC and given to codec input and capturing the same through SAI interface . Now how to conclude that signal frequency is 1Khz by using SAI captured samples.

I was suggested to do FFT on those samples ,

>> Is it possible to do FFT on captured sample from SAI interface.

>> To do this Is there any inbuilt algorithm available in CMSIS library. If so which one to use and how to use can anyone suggest me .

#sai #stm32f7
20 REPLIES 20
Posted on February 23, 2018 at 11:45

Hello Clive.,.,

Thank you for the reply.

I have gone through the example you have referred , In that i found following 3 function calls

   arm_cfft_f32(&CFFT_LENGTH,(float32_t*) sine_sample,1,0);

   arm_cmplx_mag_f32((float32_t*) sine_sample,pDst,512);        

   arm_max_f32(pDst,512,&MaxValue,&testIndex);

But if I use these function in my application it giving number of errors, I have included all required header files. 

Also in these example which one is the frequency parameter , Can just brief me how use those functions , or if you can provide some aPP note it will be more helpful.

Thank you.,

Posted on February 23, 2018 at 11:56

What is the error, probably most likely a linker error and you haven’t added the library to your project.

you don’t get frequency directly out of a FFT, you get the bin index which contains the biggest magnitude, depending on the sample rate and fft size you will find that each bin spans a number of frequencies.

also beware that bin 0 contains DC, so it’s probably best to zero that before doing the max magnitude call.

Posted on February 23, 2018 at 11:58

The example should show you how to use the functions.

Just plug in your input data, and call it periodically (if required).

But if I use these function in my application it giving number of errors, I have included all required header files.

You need to add these FFT sources to your project as well.

'giving a number of errors' is not quite an accurate description, better show the actual error messages.

Posted on February 23, 2018 at 11:58

Edwin kaus wrote:

it giving number of errors,

Don't you think that it would be necessary to know what, exactly, those errors are in order to be able to say anything about how to fix them ... ?

As others have said, might it not be simpler to just do the analysis on a PC?

eg, Audacity can directly give you the spectrum of an audio signal - no programming required ...

https://www.audacityteam.org/

  
Posted on February 23, 2018 at 12:18

Hello.,

Most probably I have missed some libraries to be add, that I will try to solve . 

But I need some detailed explanation to get frequency after FFT, Is it any arithmetic operation required on Magnitude and index values, Can you provide those formulas required. 

Posted on February 23, 2018 at 12:26

So, again, why DIY  - and why on the target?

https://community.st.com/0D70X000006T01pSAC

 

https://community.st.com/0D70X000006T01pSAC

 
Posted on February 23, 2018 at 12:34

Sample rate/fft length = bin width

max index * bin width = frequency in the bin of the largest magnitude signal.

for example, a 44khz sample rate with an fft of 512 will give you 86hz per bin.

so if bin 2 contains the biggest magnitude then the frequency is 172 hz.

Posted on February 23, 2018 at 12:39

Seems that including code that involves operations unfamiliar to you is introducing more trouble, instead of testing/verifying the codec.

PC based applications (like the suggested Audacity), would do all that for you.

Posted on February 23, 2018 at 12:50

Hello.,

I understand your concern , Yes its so simple to do it on PC and I have done those thing already. But in our application I need to test all on board available resource by its own and then its goes for application mode. So this is very important requirement to test audio codec. 

Posted on February 23, 2018 at 13:14

Hello.,

Here in my application audio signal is captured at 16Khz sampling frequency, suppose if I do FFT for 512 words(16bits). How to apply above formula to get frequency.