Skip to main content
improved formatting + additional tag
Source Link
Gilles
  • 3.4k
  • 3
  • 23
  • 29

frequency Frequency extracted from fft (matlab)MATLAB's $\tt fft$ is not very accurate

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?

frequency extracted from fft (matlab) is not very accurate

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 its fft. After computing the 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 'bin' no. 16 corresponds to

$\frac{frequencyBin \times sampling frequency}{no. of samples} = \frac{16 \times 1000}{1500} = 10.6667$

however I know that my frequency I hardcoded is actually 10. 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

Frequency extracted from MATLAB's $\tt fft$ is not very accurate

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?

Source Link

frequency extracted from fft (matlab) is not very accurate

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 its fft. After computing the 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 'bin' no. 16 corresponds to

$\frac{frequencyBin \times sampling frequency}{no. of samples} = \frac{16 \times 1000}{1500} = 10.6667$

however I know that my frequency I hardcoded is actually 10. 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