As a test I made up a sine wave in matlabMATLAB of this form
y = 5*sin((2 * pi * freq).*x + 1.4) - 6;
where freq
is 10
and x
varies from 0$0$ to 1.5$1.5$ with a resolution of 1/10001/1000
as shown below
fs = 1000;
x = 0:1/fs: 1.5 - (1/fs);
So iI already know the frequency to be able to verify its fftit with fft
. After computing the fftamplitude FFT abs(fft(yy))
, I find that the frequency bin with the highest magnitude is 16
$16$. Since I have 1500$1500$ samples which correspond to a sampling frequency of 1000$1000$ then 'bin' no.the 16$^\rm{th}$ bin corresponds to
$\frac{frequencyBin \times sampling frequency}{no. of samples} = \frac{16 \times 1000}{1500} = 10.6667$$$\mathrm{\frac{Frequency \ Bin \times Sampling \ Frequency}{Number \ of\ Samples} = \frac{16 \times 1000}{1500} = 10.6667\ Hz}$$
howeverHowever I know that my frequency I hardcoded is actually 10$10\ \rm Hz$. This can be repeated with different values and the same inaccurate result keeps occurring. andAnd the smaller the hardcoded frequency the larger the error in the result. Why is this happening?