# DFT Examples

For understanding what follows, we need to refer to the Discrete Fourier Transform (DFT) and the effect of time shift in frequency domain first. Here, we discuss a few examples of DFTs of some basic signals that will help not only understand the Fourier transform but will also be useful in comprehending concepts discussed further.

## A Rectangular Signal

A rectangular sequence, both in time and frequency domains, is by far the most important signal encountered in digital signal processing. One of the reasons is that any signal with a finite duration, say $T$ seconds, in time domain (that all practical signals have) can be considered as a product between a possibly infinite signal and a rectangular sequence with duration $T$ seconds. This is called windowing and a rectangular sequence is the simplest form of a window. Windowing is a key concept in implementation of many DSP applications.

Let us compute the $N$-point DFT of a length-$L$ rectangular sequence
\label{eqIntroductionRectangular}
s_I[n] = \left\{ \begin{array}{l}
1, \quad n_s \le n \le n_s+L-1 \\
\end{array} \right.

shown in Figure below, where $N \ge L$.

Since this sequence is real with no $Q$ component in time domain, the $I$ component in frequency domain from DFT definition can be expressed as
\begin{align}
S_I[k] &= \sum \limits _{n=n_s} ^{n_s+L-1} s_I[n] \cos 2\pi\frac{k}{N}n \nonumber \\
&= \sum \limits _{n=n_s} ^{n_s+L-1} \cos 2\pi\frac{k}{N}n \label{eqIntroductionDerivation1} \\
&= \sum \limits _{n=n_s} ^{n_s+L-1} \cos 2\pi\frac{k}{N}n~ \frac{\sin \pi\frac{k}{N}}{\sin \pi\frac{k}{N}} \nonumber
\end{align}

Let $\theta = 2\pi k/N$ and using the identity $\cos(A)\sin(B) = 0.5 \{ \sin(A+B) – \sin(A-B) \}$, we get
\begin{align*}
S_I[k] &= \sum \limits _{n=n_s} ^{n_s+L-1} \cos n\theta~ \frac{\sin \theta/2}{\sin \theta/2} \\
&= \frac{1}{2\sin \theta/2} \sum \limits _{n=n_s} ^{n_s+L-1} \left[ \sin \left( n+\frac{1}{2}\right)\theta – \sin \left( n-\frac{1}{2}\right)\theta \right] \\
&= \frac{1}{2\sin \theta/2} \left[ \sin \left( n_s+L-\frac{1}{2}\right)\theta – \sin \left( n_s-\frac{1}{2}\right)\theta \right] \\
\end{align*}
where all the other terms in the summation cancel out. Using the same identity as above
\begin{align*}
S_I[k] &= \frac{1}{\sin \theta/2} \cos \left(n_s + \frac{L-1}{2}\right)\theta \cdot \sin\left(\frac{L}{2} \right)\theta \\
&= \frac{\sin L \theta/2}{\sin \theta/2} \cos \left(n_s + \frac{L-1}{2}\right)\theta \nonumber
\end{align*}
Plugging in the expression back for $\theta$,
\begin{align}
S_I[k] &= \frac{\sin \pi L k/N}{\sin \pi k/N} \cos \left[ 2\pi \frac{ k}{N}\left(n_s + \frac{L-1}{2}\right) \right]\label{eqIntroductionDFTrectangleI}
\end{align}

Similarly, $Q$ component can be found from DFT definition,
\begin{align*}
S_Q[k] &= \sum \limits _{n=n_s} ^{n_s+L-1} -s_I[n] \sin 2\pi\frac{k}{N}n \\
&= \sum \limits _{n=n_s} ^{n_s+L-1} -\sin 2\pi\frac{k}{N}n
\end{align*}

Following the same procedure as $I$ component, and using the identity $\sin(A)\sin(B) = \frac{1}{2}$ $\left\{ \cos(A-B) -\right.$ $\left. \cos(A+B) \right\}$, the $Q$ component of its DFT is given by
\begin{align}
S_Q[k] &= -\frac{\sin \pi L k/N}{\sin \pi k/N} \sin\left[ 2\pi\frac{k}{N} \left(n_s + \frac{L-1}{2}\right) \right]\label{eqIntroductionDFTrectangleQ}
\end{align}

Despite its simplicity, there is a lot of information hidden and several interesting conclusions to be drawn here for which we continue further discussion below.

### Magnitude and Phase

Applying the definitions of magnitude and phase to Eq \eqref{eqIntroductionDFTrectangleI} and Eq \eqref{eqIntroductionDFTrectangleQ} and using $\cos^2 A + \sin^2 A = 1$, we get the magnitude and phase of the DFT of a rectangular signal.

|S[k]| = \frac{\sin \pi L k/N}{\sin \pi k/N} \label{eqIntroductionDFTrectangleM}

\measuredangle S[k] = -2\pi\frac{k}{N} \left(n_s + \frac{L-1}{2}\right) \label{eqIntroductionDFTrectangleP}

The above Figure displays the magnitude and phase plots for the DFT of a rectangular signal with $L=N=16$ which in this case are similar to the $I$ and $Q$ plots, respectively. In general, magnitude-phase and $IQ$ plots convey different information, many examples of which we will encounter throughout this text. In most situations, magnitude-phase plot delivers a great deal of information while in some others, $IQ$ plot is more relevant.

### DFT, Frequency Domain Sampling and Leakage

For DFT of a rectangular signal, the $IQ$ equations are given in Eq \eqref{eqIntroductionDFTrectangleI} and Eq \eqref{eqIntroductionDFTrectangleQ}, and the magnitude-phase equations in Eq \eqref{eqIntroductionDFTrectangleM} and Eq \eqref{eqIntroductionDFTrectangleP}. The corresponding figures are drawn in the Figure above with single impulses at bin 0.