# How to find the Freqs bins

Ok, so I'm kind of moving forward with implementing the STFT. I realise that I was taking the entire FFT and not the first half.

The problem that I'm having now is, understanding how to get the Freq bins, what calculation should I use? For example, I have been using this formula:

(10 * log10(sqrt(v[i][j].re * v[i][j].re + v[i][j].im * v[i][j].im)));


Which, I realise that this is for decibels. Currently, my graph looks like the following:

I know this makes sense to me now, this is finally starting to come together!

Would this algorithm work?:

I take the magnitude of each of the elements inside the bin mags = (re * re + im + im) I then find the maximum index of the bin, multiply it by the Fs and divide by the bin size?

If I did this, however, would this only give me 1 result for each block?

## 1 Answer

Your Y axis likely should be scaled to frequency (Hz), not FFT bin index [0..127]. The frequency scale would be something like the bin_index * sample_rate / FFT_length .

• These can be set during the actual plotting of the spectrogram, though? So effectively, I need to create another array to store the frequency (htz).. BUT, do I therefore calculate the frequency for each of the FFT bin index? At the moment, I'm plotting the abs of the complex number.. So essentially, sqrt(re*re+im*im) and plotting these values.. Is this correct? Commented Jan 16, 2014 at 15:18
• Hz just for the Y axis lettering (in place of the 20,40,80...120 in your above plot), not for each bin. Commented Jan 16, 2014 at 16:55
• I don't get what you mean, please could you elaborate on this please? At the moment, I'm plotting the abs of the complex number sqrt(re*re+im*re) Should I therefore not plot the abs number, instead plot the frequency scale bin_index * sample_rate / FFT_LENGTH or should these values be in a separate array and in Python do x = np.array(freqs); plt.setyaxis(freqs);? Thanks, this is the last thing that is confusing to me Commented Jan 16, 2014 at 22:29
• sqrt(re*re+im*im) Commented Jan 16, 2014 at 22:49
• That cannot work. Since calculating the Htz of each of the STFT blocks (re*re+im*im) will return the same max index 128` where the same rate is 12000 will always return 6000 for each of the blocks.. Any ideas? Commented Jan 17, 2014 at 18:19