Hmmm… Great thanks for your reply.
Actually I’ve already found out that I get the best result when I assume the lowest freq is 0 Hz.
But then I have problem how to draw it on my chart where Hz are in log scale, so for log10( 0 Hz ) I get undefined value (actually infinity).
Of course I don’t need to draw 0 Hz, while it always has amplitude zero. So my bin 0 is always zero.
I calc the freq by the formula:
nyquistFreq = sampleRate / 2;
for(int bin = 1; bin < fftSize; ++bin)
{
hz = bin * nyquistFreq / fftSize;
x = log10(hz);
...the rest of code...
}
So as you can see I start my loop from bin 1 (not zero), and it is OK but only for big fftSize.
Let’s say I want to show on my chart all frequencies from 20Hz to 20000Hz.
So while hz = 1 * nyquistFreq / fftSize;
is less than 20Hz it is OK.
But the problem start when I have lower fftSize, like let’s say 128. Than all things concern to 20Hz I have in bin zero, then I can’t start my loop from 1. I need to use in some way the bin zero.
But I also can’t start loop from zero, because log10( 0 ) will give me infinit value.
So I need to rethink it. Have you got any idea how should it be done?
The value at bin=0 is a special value called DC offset. If your block is well balanced it should yield 0, but it doesn’t have to.
And don’t confuse the nyquist frequency with the samplerate. Nyquist = sampleRate / 2, see wikipedia
The formula is f (hz) = bin * sampleRate (1/s) / fftSize
Writing the units helps to catch errors early on.
You can verify your formula on stackexchange