Monday, September 10, 2018

FFT resolution and sampling frequency


I am computing FFT of the data which I am receiving from an ADC with SPI protocol. Since resolution of FFT is related to $F_s/N$ where $N$ is the FFT length and $F_s$ is the sampling frequency of ADC, when I lower sampling frequency, it should decrease frequency range that I see due to Nyquist–Shannon sampling theorem and conversely it should also increase my FFT resolution.


I am plotting this FFT in realtime and I've given 1 Hz sinusoidal signal via arbitrary signal generator and tested various sampling frequencies to see which point 1 Hz equals to.


╔═══╦═══════════════╦═══════════════╗
║ ║ Sampling Freq ║ Point of 1 Hz ║ 0. point included
╠═══╬═══════════════╬═══════════════╣
║ 1 ║ 20k ║ 3 ║

║ 2 ║ 10k ║ 6 ║
║ 3 ║ 1k ║ 9 ║
║ 4 ║ 100 ║ 9 ║
╚═══╩═══════════════╩═══════════════╝

No matter how I lower sampling frequency, it doesn't go further than 9. By the way, my FFT length is 1024.



Answer



One issue is that, for the first two sampling frequencies, you are not sampling a full wave of the signal.


Below is a plot of the time domain signal (1024 samples) and the resulting FFT. For the first two, the DC bin (0 index) will capture all the energy. For the 1kHz example, the first bin (the one after 0 index) will capture it. Bin 10 is where the peak is for 100 Hz sampling rate.


Perhaps your sampling isn't happening quite the way you expect?



enter image description here




R Code Below


# 43563

N <- 1024

fs <- c(20000, 10000, 1000, 100)
res <- c(0,0,0,0)
idx <- 1


par(mfrow=c(4,2))
for (freq in fs)
{
res[idx] <- freq / N
idx <- idx + 1
t <- seq(0,N-1) / freq
x <- sin(2*pi*t + 0.892340923)
plot(x, type='l')
title(paste('time domain for ', freq))

x_fft <- abs(fft(x))
plot(x_fft[1:100], type='l')
title(paste('100 bins in frequency domain for ', freq))
}

No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...