# What's Nyquist frequency in DFT?

I'm currently studying digital signal processing at university but I can't figure out what the Nyquist frequency means in the DFT coefficients, I know what the Nyquist frequency is in the sampling theorem but why in the DFT one of the coefficients is the Nyquist frequency and what does it mean practically? I mean, consider the following MATLAB code:

fc=100; %sampling freq [Hz]
T = 1/fc;
N = 6;  %number of samples
fft( (0:N-1)*T );


which output is:

0.1500 + 0.0000i  -0.0300 + 0.0520i  -0.0300 + 0.0173i
-0.0300 + 0.0000i -0.0300 - 0.0173i  -0.0300 - 0.0520i


from the DFT theory, I know that the Nyquist frequency should be:

 -0.0300 + 0.0000i


but how can I interpret this result? what does it mean practically? I hope someone can help me, thanks

• Fun fact: Nyquist only turns up in the DFT if you have even DFT length. Commented Apr 12 at 11:55

In a sampled system, the Nyquist Frequency is $$f_s/2$$ where $$f_s$$ is the sampling rate. Each bin in a N sample DFT is centered on frequency $$f=k f_s/N$$ with $$k$$ indexed from $$0$$ to $$N-1$$. Thus in an $$N=6$$ sample DFT as in the OP’s example, the Nyquist Frequency occurs at $$k=3$$ resulting in $$f=3 f_s/6= f_s/2$$.

Also we see from this that in an odd sample DFT ($$N$$ odd), the Nyquist frequency will be half way between two DFT bins.

As far as interpreting the results for the Nyquist bin as well as any of the other bins, we can relate the results to the Fourier Series Expansion (as one interpretation from continuous time Fourier theory), where each coefficient is the weighting of that frequency for which we could sum each of the terms and recreate the time domain waveform: The OP has taken the DFT of a real ramp function in time. The Fourier Series of a ramp consist of a series of frequencies each at integer harmonics at $$f=1/T$$ where $$T$$ is the time duration of the ramp, with each term having a magnitude that goes down at $$1/n$$ where $$n$$ is the harmonic number. Once sampled, any frequency content above Nyquist folds back into the primary frequency range extending from $$DC$$ to Nyquist (it may be very helpful to review sampling theory first if the concepts of aliasing and folding are not clear).

With that in mind, consider a plot showing the magnitude for the OP's result. Bin 0 is the "DC Bin" and bins 1, 2 and 3 are the bins corresponding to the fundamental frequency at bin 1, and the 2nd and 3rd harmonic with the 3rd harmonic landing right on the Nyquist frequency. The higher frequency components represent the "negative frequencies", which for a real time domain waveform will be the complex conjugate of the "positive frequencies" and therefore can be ignored due to their redundancy (we see this here in how bins 4 and 5 are a mirror of bins 2 and 1; and in the OP's results they have the exact same magnitude and opposite phase).

The Fourier Series of a continuous time ramp would have continued with higher harmonics with the magnitude continuing to go down at the reciprocal of the frequency index - those terms in this case have aliased back in, modifying the levels we see for the first 4 terms.

If we repeated the OP's experiment with many more samples (increasing the total time duration such that the fundamental frequency of the ramp is much lower), then we will see a lot more harmonics of the ramp before aliasing occurs. Below is the result repeating the OP's test with $$N=50$$ showing this:

Here we see a large DC term (consistent with the ramp as the OP has created it, which has a large DC offset or mean value), and we see the fundamental frequency at bin $$k=1$$, with all higher harmonics with a magnitude reducing by $$1/k$$. As we approach Nyquist, the magnitude will be modified due to the aliasing that occurs from the components above Nyquist. I also added a dashed black line showing the predicted magnitude of the harmonics for the continuous time ramp prior to being sampled. Zooming in near Nyquist (at $$k=50$$) and we can see the magnitude change which can be explained as aliasing distortion.

• Thanks for your very complete answer, there are some points that I'm missing, when you say: " In a sampled system, the Nyquist Frequency is $fs/2$ where $fs$ is the sampling rate. " how does the DFT know what sampling frequency was used to sample the signal? I'm a little bit confused because I know that DFT does periodicization in the time and frequency domains according to the sampling frequency used, so if the Nyquist frequency in DFT is related to $fs$ how does the DFT know which sampling rate has been used? I'm sorry for all these questions but maybe I'm missing something Commented Apr 12 at 13:47
• It doesn’t know— you just got 6 samples in frequency. We know what sampling rate you used because you told us. Change the sampling rate and the 4th will still be the Nyquist bin. Work through the formulas I gave you and you’ll see that it all scales with the sampling rate—— with the DFT we have 6 samples in time corresponding to 6 samples in frequency—- if you sample faster or slower you can still use 6 samples (or any N) and get the result I gave Commented Apr 12 at 13:57
• So in the example there is aliasing just because the spectrum of the ramp is not band-limited, so it doesn't verify the Nyquist condition (sampling theorem) $fs>=2B$ where $B$ is the mono-lateral band of the signal, am I right? I tried to calculate the Fourier series coefficient of the signal and they're different from the DFT results, I think at least the DC should be the same. Commented Apr 12 at 20:58
• Yes that is correct. Yes it matches the Fourier Series. Depending on how you are computing that, you may need to divide the DFT result by the total number of samples (The first coefficient at $f=0$ for the Fourier Series corresponds to the average or DC value in time, the first bin of the DFT divided by $N$ is the average of the time domain signal- same thing. Commented Apr 12 at 23:03