# DFT sinusoid's fundamental frequency, intuitively

I am trying to understand, intuitively, the mapping of a sinusoidal signal's fundamental frequency from time domain to frequency domain using $\textrm{DFT}$ formula. Given the time domain samples $\{x[0], x[1], \dots, x[N - 1]\}$; we have from the $\textrm{DFT}$ formula:

$X(f_k) = \displaystyle \sum_{n = 0}^{N - 1}x[n]\exp\left(-j2\pi f_kn\right)\tag{1} \label{dft}$

for $f_k = k/N$ and $k =0, 1, \cdots, N - 1$.

For this purpose I used a sinusoidal signal in Matlab and its windowed version. Here is an excerpt from my Matlab code:

Fs = 1000;
Ts = 1/Fs;
t = 0:Ts:(1000 - 1)*Ts; %1sec

A = 2;
F = 20;
y1 = A*sin(2*pi*F*t);
y2 = y1.*hann(length(y1))';

nfft = 2^nextpow2(length(y1));
Fy = (Fs/2)*linspace(0, 1, nfft/2+1);

Y1 = 2*abs(fft(y1, nfft));
Y1(1) = .5*Y1(1);
Y1 = Y1./max(Y1);

Y2 = 2*abs(fft(y2, nfft));
Y2(1) = .5*Y2(1);
Y2 = Y2./max(Y2);


See the figure below for the time domain and frequency domain plots of the signals

I have two questions:

1. How can one intuitively see that the linear combination of exponentials from $\eqref{dft}$ will yield a sum with an absolute amplitude $\left| X(f_k)\right|$ that has a maximum at the fundamental frequency $\textrm{F = 20 Hz}$ ? Or is this an optimization problem of the absolute amplitude spectrum $\left|X(f_k)\right|$ wrt to $f_k$ ? Or is this just the magic of the $\textrm{DFT}$ ?

2. How is the tapering of the signal by non-rectangular window explain from $\eqref{dft}$ the better localization of the maximum at $\textrm{F = 20 Hz}$ (i.e minimized leakage around the fundamental frequency) ? I am well aware of the theory on windows, leakages. I'm more looking for an explanation based on equation $\eqref{dft}$. From the visual inspection of $y_1$ and $y_2$ on the top figure, how could one conclude, from the linear combinations in $\eqref{dft}$, the difference of shapes in $\left|Y_1(f_k)\right|$ and $\left|Y_2(f_k)\right|$?

• i noticed that you have exactly 20 cycles of the sinusoid in the plotted window. is that your entire DFT length? it appears to be so and that your DFT would be operating on a length 1000 block of data. then, for the rectangular window (which is really no window at all), the spike at 20 Hz should be 1 FFT bin thick. there should be no little blue "skirts" on the side as shown. not if there are exactly an integer number of cycles in the FFT input buffer. Jul 18 '15 at 4:06
• @robertbristow-johnson Yes. I have a 20 Hz signal for a second of duration, hence the 20 cycles. It is the entire length DFT, but took the single side. The DFT is 1024 block, 1000 data plus 24 for the padding. Having the Fs and NFFT be multiples of each other seems to give a reasonably better blue plot around the fundamental frequency. Jul 18 '15 at 14:01
• "The DFT is 1024 block, 1000 data plus 24 for the padding." and "... hence the 20 cycles. It is the entire length DFT..." are inconsistent with each other. your 20 cycles do not take up the entire DFT length. if they did, there would be a single non-zero bin in the positive frequencies (bin 20) and a single bin in the negative frequencies (bin 1004, which is 1024-20) and no little skirting or sidelobes around that single spike. Jul 19 '15 at 2:48
• Well, then I would say to you that it is not necessarily the case that "... the tapering of the signal by non-rectangular window explain from (1) the better localization of the maximum..." A rectangular window of 1024 points (which is really no window at all) with the sinusoid making exactly 20 cycles in that aperture, that will show the maximum more clearly and accurately than anything else. Jul 20 '15 at 2:09
• @Gilles The DFT is a projection of a signal onto a sum of harmonically related sinusoids. The the projection of a sinusoid onto any harmonically related sinusoid over the period of the lowest-frequency sinusoid is 0 unless the two sinusoids have the same frequency. (Try multiplying two sinusoids of different frequencies and then integrating over the period of the sinusoid). The nature of sinusoids is that they only project onto themselves and project no energy onto other sinusoids. If you think about it this way, it may help you develop intuition about what happens with the DFT. Jul 23 '15 at 16:51