cancel
Showing results for 
Search instead for 
Did you mean: 

FFT with STM32F4 not giving correct frequency output

akshay bansod
Associate II
Posted on June 20, 2018 at 11:57

The original post was too long to process during our migration. Please click on the attachment to read the original post.
1 ACCEPTED SOLUTION

Accepted Solutions
Tilen MAJERLE
ST Employee

Posted on June 20, 2018 at 12:52

Hello,

FFT works on sinus signal. For 25Hz square, you have (theoretically) unlimited number of frequencies with different amplitudes.

In general, FFT input must be 2^n samples and you will also receive back 2^n samples. These samples are mirrored by center frequency between 0 and sampling frequency, which means that your 'useful' data are only between 0 and Fs / 2. Result of FFT is not frequency number. You have to interpret your result properly to decide where to find your frequency.

Example:

Sampling frequency Fs = 45kHz

Number of samples for FFT calculation FFT_SIZE = 1024

Calculations:

Frequency resolution on output = Fs / FFT_SIZE = 45000 / 1024 = ~44Hz. You can detect frequency of [0, 44, 88, etc..., 45000-44] Hz

Useful data = FFT_SIZE / 2, which means frequency bands from [0, 44, 88, ..., 45000/2 - 44] Hz

If you are interested in result at 88Hz, you have to check output[2] array value. output[0] is equal to DC value in signal.

Very fast and very basic. You have to take care now that your ADC sampling is really 45kHz and then interpret FFT result properly.

Best regards,

Tilen

View solution in original post

4 REPLIES 4
Tilen MAJERLE
ST Employee

Posted on June 20, 2018 at 12:52

Hello,

FFT works on sinus signal. For 25Hz square, you have (theoretically) unlimited number of frequencies with different amplitudes.

In general, FFT input must be 2^n samples and you will also receive back 2^n samples. These samples are mirrored by center frequency between 0 and sampling frequency, which means that your 'useful' data are only between 0 and Fs / 2. Result of FFT is not frequency number. You have to interpret your result properly to decide where to find your frequency.

Example:

Sampling frequency Fs = 45kHz

Number of samples for FFT calculation FFT_SIZE = 1024

Calculations:

Frequency resolution on output = Fs / FFT_SIZE = 45000 / 1024 = ~44Hz. You can detect frequency of [0, 44, 88, etc..., 45000-44] Hz

Useful data = FFT_SIZE / 2, which means frequency bands from [0, 44, 88, ..., 45000/2 - 44] Hz

If you are interested in result at 88Hz, you have to check output[2] array value. output[0] is equal to DC value in signal.

Very fast and very basic. You have to take care now that your ADC sampling is really 45kHz and then interpret FFT result properly.

Best regards,

Tilen

Posted on June 20, 2018 at 14:23

Hello

Majerle.Tilen

‌,

Thank you for the instant help.

Understood & got the output correctly.

Posted on June 22, 2018 at 00:43

Hello,

you may want to read post on link below:

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

 

Best regards,

Tilen

hi bro. I'm studying about that. Can you give me your project after fix this problem. Thanks so much !!!