2

I am doing a fft (stft) on a audio-file, which contains voice and music. I took out a range of 1-200 from signal, which i saved in a variable called, for example, frequency_band1. How can i calculate the frequency bins from variable, which stores my specificially chosen signal, on which the fft was applied before.? I think, read somewhere, that i needed to calculate fs/fftpoints. In my case, 44100/4096. Do i multiply it with my variable frequency_band1*(44100/4096)? This is done on matlab, and i need to do it, with a stft.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • The output values of a DFT (FFT) are at frequencies `[0:n-1]/n*fs` where `n` is DFT size and `fs` is sample frequency – Luis Mendo Jan 26 '17 at 22:21
  • @Lusi Mendo, with "n", do you mean the fft points? I am not quite sure, since i am a newbie at matlab. How is this linked to my question, if you could enlighten me, i would really appreciate it. – CidelFastro Jan 26 '17 at 22:50
  • I've included an answer with an example – Luis Mendo Jan 26 '17 at 22:57
  • @Luis Mendo Ok, thank you, now i got it. One last question, sorry for being annoying btw, but does "numel" stands for the number of elements from the sinusoid, so that you can create a frequency vector? – CidelFastro Jan 26 '17 at 23:06
  • Yes, `numel` is size of the vector `x`. You should actually use the size of the output of `fft`, in case it's different from the size of the input (that is, if you use a second argument to `fft`). I've edited that – Luis Mendo Jan 26 '17 at 23:10
  • @Luis Mendo, ok thank you very much, for help! – CidelFastro Jan 26 '17 at 23:19
  • Glad I could help! – Luis Mendo Jan 26 '17 at 23:19

1 Answers1

0

The output values of a DFT (FFT) are at frequencies (0:n-1)/n*fs where n is DFT size and fs is sample frequency.

Here's an example. This creates a sinusoid at a known frequency, performs the DFT of the whole signal (so n is signal size), and plots the spectrum using the above as frequency values.

fs = 44100; % sample frequency
t = 0:1/fs:.1; % 0.1-second time axis
x = sin(2*pi*300*t); % sinusoid of frequency 220 Hz
X = fft(x); % DFT of x
f = (0:numel(X)-1)/numel(X)*fs; % frequency axis of DFT
plot(f, abs(X)) % plot the spectrum in absolute value
grid % add grid
axis([0 1000 -500 2500])

You can check that the spectral line of this signal is where it should, that is, at 300 (Hz).

enter image description here

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147