meekm / LoRaSoundkit

This Soundkit sensor measures continuously audible sound by analyzing the data using FFT
19 stars 5 forks source link

Frequency calculations #6

Closed rdkluijv closed 2 years ago

rdkluijv commented 2 years ago

I'm lost when I look at the frequency calculation. First: With 2048 samples multiple by 11 is 22528. Why use 22628? Second: With 22628 the maximum frequency that can be detected is 22628 / 2 = 11314 Hz. (Shannon) With a 2048 length vector from the FFT I would expect a resolution of 5,5 Hz. What's wrong with my calculation?

meekm commented 2 years ago

Answer 1: The reason why this sample frequency has been chosen, is to map the bins nicely around the center frequency of the octaves. Thus measuring the energy of octave 31,25 Hz is the sum of exactly bin 1 and bin 2, which is the frequency range 22Hz to 44Hz. The measuring of octave 62,5 Hz is the sum of the energy in bin 3 up to 6, which is the frequency range 44Hz to 88Hz etc ...

Answer 2 Correct, te highest frequency is sample frequency /2

Answer 3 The resolution is the bin size, which is sample frequency devided by buffersize, which is 22628/2048 is 11 Hz

meekm commented 2 years ago

First: With 2048 samples multiple by 11 is 22528. Why use 22628?

To be exactly the bin size is not 11Hz but 11,0485Hz which is (31,25Hz / sqrt(2) )/2.

Second: With 22628 the maximum frequency that can be detected is 22628 / 2 = 11314 Hz. (Shannon)

I agree with this.

With a 2048 length vector from the FFT I would expect a resolution of 5,5 Hz. What's wrong with my calculation?

The bins represent energy levels, there are 1024 bins of 11,0485Hz each, used to cover the frequency range from 0 to 11314 Hz. The other half of the FFT buffer is a mirror of the first half and is useless.

rdkluijv commented 2 years ago

Thanks for the explanation. I'm still confused so I'll try to explain my calculation. For me the indexes of the buffer represent frequency ranges. It is a conversion from the time domain to the frequency domain. (Ignoring the fact that the signals are sampled so discrete.) The lowest frequency I want is 31,25 Hz. So the highest resolution, the most narrow band of frequencies, is 2/3 31,25 Hz (20,83... Hz). That 1/3 31, 25 Hz below 31,25 Hz and 1/3 31,25 Hz above it. Index = 0 is the band from DC to 20,83... Index = 1 is the band from 20,83... to 220,83..., centered around 31,25 Hz Index = 2 is the band from 220,83... to 320,83..., lower part of 62,5 Hz Index = 3 is the band from 320,83... to 420,83..., higher part of 62,5 Hz 125 Hz has indexes 4 to 7. 250 Hz has indexes 8 to 15. Etc. for higher values. Now for a buffer of size 16, I get a frequency of 16 20,83... or 16 2/3 * 31,25 = 333,33... Hz. This will give me the number of indexes and the max frequency in the frequency domain. The sample rate in the time domain is twice the max frequency in the frequency domain. For 8 kHz the max frequency is 10,66... kHz with a sample rate of 21,333 kHz. I fail to understand why the amplitude matters.