0
$\begingroup$

This question is in two parts, both related in some way or another.

Suppose I have a signal where the sample rate is 44100 and compute a normal 1D DFT on this signal. The size of this signal is 220500. I need to compute the Hertz for the outputted DFT.

I calculate the bins using the formula below:

sqrt(output[i].re * output[i]. re + output[i].im * output[i].im)

I then find the maximum number in this vector and compute the following:

freq = max * 44100 / fft.size() 

This then gives me a result of: 4526.84

I don't know, something seems to be wrong here, the duration of the file is 0:05 is this result expected or unexpected? I'm sure I need to take into account the number of seconds, but I was lead to believe that the resulting answer should be that of the sample rate (44100)

Question 2:

Let's suppose I've computed a STFT of this signal of size 256 with an overlap of 128, let's suppose I want to calculate the frequency of each of these segments, or, parts, since this will now effectively be a 2D vector. Do I therefore need to calculate this using the formula above, where the FFT size in this case will infact be 256.

Any help would be greatly appreciated :)

$\endgroup$
  • $\begingroup$ Why did you think that the result should be the sample rate? $\endgroup$ – Jim Clay Jan 9 '14 at 21:30
  • $\begingroup$ @JimClay I don't really know. I just picked this up as an observation. I made a simple mono sine wave at 500Hz and got: 10146.4 as a result.. So need to re-think where I'm going wrong $\endgroup$ – Phorce Jan 9 '14 at 21:34
1
$\begingroup$

Your calculation of the frequency of a given bin is correct:

$$ Freq = \frac{binNumber}{numberOfBins}F_s $$

I suspect that the problem is that you are setting the bin number to the maximum bin power instead of the index of the bin with the maximum power.

$\endgroup$
  • $\begingroup$ by "index of the bin with the maximum power" do you mean the point where it is in the signal/array and not the number itself? $\endgroup$ – Phorce Jan 9 '14 at 21:39
  • $\begingroup$ Yes, that is what I mean. $\endgroup$ – Jim Clay Jan 9 '14 at 22:10
  • $\begingroup$ Mind you, for negative frequencies it is slightly more complex, but I didn't want to introduce that complication. $\endgroup$ – Jim Clay Jan 9 '14 at 22:18
  • $\begingroup$ How do you mean? This currently isn't working. I generated a 10hz sound file from: audiocheck.net/audiofrequencysignalgenerator_sinetone.php ... The max index is: 440895 where the size is 441001.. My calculation therefore: 440895 * 44100 / 441001 = 44089.4 So where am I going wrong here? $\endgroup$ – Phorce Jan 9 '14 at 22:29
  • $\begingroup$ Would passing the FFT bins through a window function make any difference here? $\endgroup$ – Phorce Jan 9 '14 at 22:34

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.