Reputation: 4642
This question is mainly related to this answer: Here so would be ideal if @Paul R has a chance to look at it.
I have a signal, which I have computed a STFT on. The size of the NFFT is 256 with an overlap of 128. This has produced 21 separate blocks containing the output.
I would like to therefore convert this into Hertz to see what the different Hertz are for each of these points within the signals. I have computed the magnitude using the following formula:
sqrt(output[i][j].re * output[i][j].re + output[i][j].im * output[i][j].im)
This produces the following:
I'm mainly confused with how the next part works. For example I essentially have a 2D vector containing all of the blocks from the STFT (each of size 256). Do I therefore calculate the magnitude for each of the points within the block, calculate the highest number of the magnitude and then use the formula freq = i_max * Fs / N
?
If so, would it look something like the following (An example, not actual data):
D0 = {0.23 + 1.58,
1.05 + 0.56,
0.58 + 1.38,
.....,
0.58 + 87.6}
= mag[0] = sqrt(0.23 * 0.23 + 1.58 * 1.58),
....
....
This would then produce vector of magnitudes for each of the STFT output. From there, I can calculate which is the highest (Let's say 7) and then I can compute the following:
freq = 7 * 44100 / 4
Where 44100 = Sample rate and 4 = size of the STFT block.
This would then give me what frequency each of the blocks are.
Is this correct, or, am I missing the point completely?
Upvotes: 0
Views: 795
Reputation: 3478
You're confusing a few things, your output image seems to be the all 21 blocks (FFT) together 21 * 256 = 5376 points, it's really not help nothing !
You need find the fundamental frequency for every block (NFFT=256) using:
freq = MaxMagnitudeFromThisBlockFFT * Fs / NFFT
For your case:
freq = MaxMagnitudeFromThisBlockFFT * 44100 / 256
At the end you will find 21 frequencies one for each block FFT
PS:
Your NFFT is 256 and your sample rate is 44100, then your frequency resolution is 44100/ 256 = 172,265625, if you want more accurate try NFFT= 2048 or 4096.
Upvotes: 1