# 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?

• 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? – Phorce Jan 16 '14 at 15:18
• 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 – Phorce Jan 16 '14 at 22:29
• sqrt(re*re+im*im) – Phorce Jan 16 '14 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? – Phorce Jan 17 '14 at 18:19