As a test I made up a sine wave in MATLAB of this form
y = 5*sin((2 * pi * freq).*x + 1.4) - 6;
where freq
is 10
and x
varies from $0$ to $1.5$ with a resolution of 1/1000
as shown below
fs = 1000;
x = 0:1/fs: 1.5 - (1/fs);
So I already know the frequency to be able to verify it with fft
. After computing the amplitude FFT abs(fft(yy))
, I find that the frequency bin with the highest magnitude is $16$. Since I have $1500$ samples which correspond to a sampling frequency of $1000$ then the 16$^\rm{th}$ bin corresponds to
$$\mathrm{\frac{Frequency \ Bin \times Sampling \ Frequency}{Number \ of\ Samples} = \frac{16 \times 1000}{1500} = 10.6667\ Hz}$$
However I know that my frequency I hardcoded is actually $10\ \rm Hz$. This can be repeated with different values and the same inaccurate result keeps occurring. And the smaller the hardcoded frequency the larger the error in the result. Why is this happening?
sampling frequency/fft length
so in order to get better accuracy increase the fft length. If you can't do that (not enough samples), then you'll have to settle for what you already have. $\endgroup$4kHz
? You woudn't be able to get the exact frequency then, would you (4bin*4000/1500 = 10.67
)?. $\endgroup$