1
$\begingroup$

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:

enter image description here

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?

$\endgroup$
1
$\begingroup$

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 .

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Phorce Jan 16 '14 at 15:18
  • $\begingroup$ Hz just for the Y axis lettering (in place of the 20,40,80...120 in your above plot), not for each bin. $\endgroup$ – hotpaw2 Jan 16 '14 at 16:55
  • $\begingroup$ 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 $\endgroup$ – Phorce Jan 16 '14 at 22:29
  • $\begingroup$ sqrt(re*re+im*im) $\endgroup$ – Phorce Jan 16 '14 at 22:49
  • $\begingroup$ 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? $\endgroup$ – Phorce Jan 17 '14 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.