1

I've got 16-bit mono audio data in raw format, sampled at 48 KHz. I'm using Aquila C++ library to get the spectrum of it, since I need to perform EQ on it. Here's a code snippet:

Aquila::SampleType samples[512];
Aquila::SpectrumType spect;
std::shared_ptr<Aquila::Fft> fft;

('samples' is filled with audio)
fft = Aquila::FftFactory::getFft(512);
spect = fft->fft(samples);

So the audio data is split into 512 samples, and each piece is converted to frequency domain (FFT). I want to change the "magnitude" of e.g. 2KHz and to set the magnitude of all the frequencies beyond e.g. 10 KHz to 0 (low pass filter).

My only problem with this is that I don't know the frequency range of the spectrum generated by Aquila. I mean, I personally know that the sampling rate of the audio was 48 KHz, but Aquila FFT isn't told this value, it doesn't even need it to perform FFT. How can I determine to exactly which frequency each array entry is mapped to? E.g. spect[0] = 1 Hz, spect[10] = 126 Hz, spect[511] = 22.13 KHz etc.

tselmeci
  • 125
  • 1
  • 1
  • 11
  • http://stackoverflow.com/questions/4364823/how-to-get-frequency-from-fft-result – NPE Sep 04 '14 at 06:25
  • Also http://dsp.stackexchange.com/questions/2818/extracting-frequencies-from-fft – NPE Sep 04 '14 at 06:26
  • See: http://stackoverflow.com/a/4371627/253056 – Paul R Sep 04 '14 at 08:11
  • Note also that the naïve approach of zeroing bins in the frequency domain that you describe above will produce nasty unwanted artefacts in the time domain - you need to use a smooth transition between the pass band and stop band - typically this is done with a window function. – Paul R Sep 04 '14 at 08:13
  • Thanks for the links, it's now clear. I thought FFT must explicitly be told the sampling frequency, but this isn't the case. – tselmeci Sep 04 '14 at 10:20
  • @PaulR, just asking. Are you sure that you can do filtering just by scaling the spectrum bins, and get the correct frequency response? Isn't the "classic" convolution of the signal with a proper filter kernel (be it fast with FFT+SOLA, or linear) needed to perform this kind of operation? – al01 Sep 04 '14 at 16:16
  • @alo1: yes, it's a common technique - you need to use either overlap-add or overlap-save to deal with circular versus linear convolution, and you need to use a windowing method to give smooth transitions and thereby avoid "ringing" artefacts, etc, but it's a useful technieque if you need e.g. "parametric" filtering. – Paul R Sep 04 '14 at 18:26

1 Answers1

0

As it turns out from the comments, FFT doesn't have to be explicitly told the sampling frequency used for sampling the audio signal. One another thing to watch for is that only half of the bins holds relevant information. The frequency of n'th bin in case of an 512-step FFT is:

freq = (n * sample_rate) / 512
tselmeci
  • 125
  • 1
  • 1
  • 11