I am performing a fft on a wave consisting of two simple sine waves with fft-js. The number of samples is 512 and the running time is 16 seconds. So the sample frequency is 32Hz. When looking into the resulting frequency this goes up to 15.9375 instead to the sample frequency divided by two (16 Hz). Why is this the case and is there a way to include the sample frequency divided by two?
2
votes
1 Answers
0
votes
This short Python example shows that you were right to look for the highest frequency and it is at a nonintuitive place. The Nyquist Frequency for the FFT is actually at the other end of the frequency vector:
import numpy as np
import matplotlib.pyplot as p
%matplotlib inline
T=1 # secs
d=0.1 # secs
n=int(T/d)
t=np.arange(0,T,d)
print(f'time : {t}')
freq=np.fft.fftfreq(n,d)
print(f' frequencies (unshifted) : {freq}')
sfreq=np.fft.fftshift(freq)
print(f' frequencies (shifted) : {sfreq}')
output:
time : [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
frequencies (unshifted) : [ 0. 1. 2. 3. 4. -5. -4. -3. -2. -1.]
frequencies (shifted) : [-5. -4. -3. -2. -1. 0. 1. 2. 3. 4.]
Now Paul is also right, that a proper use of the FFT should use anti-aliasing measures such that ideally the energy at the very highest frequencies are almost zero.
sampling rate
is 32 Sa/sec. It's better not to use the termsampling frequency
, because the highest frequency we sample is 16 Hz. – roadrunner66