Why are the frequencies associated with the STFT bins not representative of the energy?

I'm experimenting with a 30 Hz sine wave and I want to extract the frequencies of this, and have implemented the algorithm to do so. This gives a correct reading, well, gives 29 Hz.

I'm now wanting to compute the algorithm for an STFT. So, for this, I use NFFT = 256 with an overlap of 128, using the Hanning Window function.

This gives me a series of bins which I can then calculate the frequency formula on. However, when I graph this, the results do not seem right, for some reason: I mean, it might just be me in thinking that the results do not look right, however, if they are, why would the results be this? I just don't get it.

For example, I was expecting when the energy is low, the result would be low and thus when the energy was high, the result would be high. Let me give you another example on a more structured sound file.

Sample rate = 12000
NFFT = 256
Overlap = 128 And the STFT output for this is below: Am I doing something wrong here, or, do these results look ok?

• 1. Your plots have no axis labels or titles, so it's more work for us in trying to help you. 2. You don't show any code, so how are we supposed to know if your code is correct? 3. Your title is misleading, the frequency bins are associated with the energy. Jan 12 '14 at 23:04
• @porten - thanks for your reply. I'll update this tomorrow. I didn't change the title.. Also are you saying these results are therefore right or wrong? since you said "the frequency bins are associated with the energy".. I noticed (because this is my own implenentation; the max freq was 6000 whereas my results show 3..? Jan 12 '14 at 23:09
• Your X axis, the number of bins, don't match half the stated length of your FFTs. Jan 13 '14 at 4:40
• If NFFT = 256 for real data, then you should only plot 128 bins or points. Jan 13 '14 at 15:28
• I'm having trouble following your question for the reasons listed by @porten, but here's a link to a blog post I wrote for people with similar problems: blog.bjornroche.com/2012/07/… Jan 13 '14 at 16:46