Pregunta

I am looking at FFTW to obtain the spectrum of a sample of audio data.

As I understand it, the "plan" for the process chooses a number N of samples which corresponds to a time period of T seconds. The value of input[x] is the amplitude of the wave at time x*N/T and the complex amplitude of output[x] relates somehow to the frequency.

I know I need to apply a window function but I don't know how. The input buffer is an array of Ni samples, in general Ni!=N, and at a rate of F Hz, this corresponds to a time of Ti=Ni/F seconds with Ti!=T in general.

So how do I populate the N inputs to the FFT given Ni samples, and, given N and F, what is the frequency corresponding to output[x]?

¿Fue útil?

Solución

There are a lot of good questions and answers on this subject on SO already, but a few general pointers:

  • the spectrum of your sample will typically be time-varying
  • you usually choose a window size (== FFT size) where there will be little short-term change in the spectrum, e.g. 10 ms (frequency resolution requirements may affect this choice), so if your sample rate is e.g. 44.1 kHz then you you might choose an FFT size of say 4096.
  • the total sample is usually processed using successive windows (i.e. blocks of samples - these typically overlap, e.g. by 50%), so you actually get a sequence of time-varying spectra
  • getting frequency info from spectra is covered by this excellent SO answer
  • you need to apply a window function to each successive block of samples, prior to calculating the FFT
  • the input to the FFT will be real values (from your block of samples) - if you use a normal complex-to-complex FFT then set the imaginary parts of the input to 0
  • the output of the FFT will be complex values containing amplitude and phase information - for a real input the output is (conjugate) symmetric so only the first N/2 output bins are actually useful
  • to get a dB magnitude value from an output bin use mag_dB = 10 * log10(re*re + im*im)
  • you can plot the sequence of output spectra as a spectrogram, using colour for dB magnitude, with frequency and sample block index (== time) as the two axes

See also:

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top