I'm working with the Aquila C++ DSP library. I'm computing the FFT of a wave file (16 bit depth, single channel, 44100 sample rate). I am using a window size of 16384 to calculate the FFT spectrum.
I'm having an issue converting the the digital frequency (0/N, 1/N, ... N/N) to the corresponding analog frequency. When I apply the sample rate multiplier S,
f = S*i/N; // Convert from digital frequency to analog frequency
I get analog frequencies that are 4 times greater than what I expect.
For example, I read in a pianos A1 note. I expect this to be ~55 Hz. Instead I'm getting ~220 Hz. Refer to the photo below.
Now I'm first wondering if I'm scaling my the wrong number. However, I'm pretty sure it's correct. So now I'm curious if somehow the time domain data I'm reading is compressed by a factor of 4, such that the frequencies appear to be 4 times greater. Does anyone know if there is a common .wav file 'gotch-ya' when reading from them?
I've posted the relevant part of my code if anyone is interested.
/* sample window */
int window_size = 16384;
/* Calculate the FFT */
std::shared_ptr<Aquila::Fft> p_fft_interface = Aquila::FftFactory::getFft(window_size); // This returns a shared pointer to an FFT calculation object.
auto spectrum = p_fft_interface->fft(wave_object.toArray());
QVector<double> x(window_size);
QVector<double> y(window_size);
/* Prepare to plot & convert to analog frequency */
double max_value = 0;
for(int i = 0; i < window_size; i++)
{
x[i] = i*(sample_freq/window_size);
y[i] = abs(spectrum[i]);
if(abs(spectrum[i]) > max_value)
{
max_value = abs(spectrum[i]);
}
}