We talked about discrete frequency in a previous post. Now we explain the Discrete Fourier Transform which computes the contribution of many discrete frequencies in a given signal.

In this Figure, a continuous-time square wave was shown to be a summation of sine waves of different amplitudes. The frequency domain representation of such a square wave identifies the amplitudes of each constituent frequency (e.g., for , for , for and so on).

Similarly, the Discrete Fourier Transform (DFT) of a signal is the tool that finds out the frequency domain amplitudes present in that signal at equally spaced discrete frequency points of this Eq we encountered in the article about discrete frequency.

To understand how a set of sinusoids with discrete frequencies can sum up to a discrete-time signal of an arbitrary shape, a good analogy is the RGB colour model in which red, green, and blue colours combine together in various ways to reproduce a broad range of different colours. Figure below shows the `spectral’ contents of yellow and grey colours formed by contributions [100% 100% 0%] and [50% 50% 50%] from red, green and blue colours, respectively.

Similarly, the DFT finds corresponding contributions in a signal from each of the discrete-time complex sinusoids. These reference sinusoids given by are called analysis frequencies. For , both and components of these complex analysis frequencies are shown in this Figure.

## Definition

Let a complex sinusoid be defined as . Then, its conjugate is

What we actually want to do is correlate a finite-length signal with complex sinusoids with frequencies (where ranges from to ). For this purpose, we multiply with the complex sinusoid sample-by-sample using complex multiplication rule. Then, for with and components and , the DFT with and components and is defined as

for each . In the above equation,

- is the time domain index of input samples, .
- is the sequence of input samples, , , .
- is the index of DFT output in frequency domain, , , .
- is DFT output component, , , .
- is the number of data samples in time domain and number of bins in discrete frequency domain.

Observe from the definition that each output is just a sum of term-by-term products between an input signal and complex sinusoids whose frequencies are complete cycles in an interval of samples (or cycles per sample). An example of such sinusoids was illustrated in Figure of DFT sinusoids.

Comparing with the phase rotation rule, we can observe that DFT operation is rotating a signal clockwise. But what exactly does this mean?

Remembering that frequency is defined as the rate of change of phase (sample-by-sample here) — and if contains a component of frequency — sample-by-sample de-rotation by a complex sinusoid of the same frequency but opposite direction (i.e., ) results in an output as a single number due to phase canceling out at each step. That single number is naturally the amplitude of the complex sinusoid with frequency , an indicator of how much that sinusoid contributes to the construction of .

The whole process eventually tries to find the contribution of every such cosine/sine wave in construction of that particular input signal. In technical terms, DFT performs correlation between the input signal and reference sinusoids. We will learn about it in the article on correlation.

The relation between a signal and its Fourier Transform is usually represented as

As a reminder, for a sample rate of kHz and point DFT, the fundamental frequency of the sinusoids is Hz represented by . The other analysis frequencies are integer multiples of the fundamental frequency as

- Hz represented by
- Hz represented by

and so on. Each frequency represents one complex sinusoid, or equivalently two real sinusoids.

Owing to this expression, DFT can also be defined for frequency bins . However, the range is more natural than since the former corresponds with our notion of a real sinusoid constituting one positive frequency and one negative frequency complex sinusoid. As an example, having two impulses in discrete frequency domain at and does not seem to convey much information. However, viewing it as two impulses at and immediately makes one realize that the time domain signal is a real sinusoid with frequency .

## Inverse Discrete Fourier Transform (iDFT)

Just like DFT is used to convert a signal from time to frequency domain, Inverse Discrete Fourier Transform (iDFT) is used as an inverse process for converting a signal from frequency to time domain. iDFT is defined as

(2)

Notice that unlike DFT where the summation is over time index , summation in iDFT is over frequency index . Moreover, as opposed to DFT, the complex sinusoids here have a counterclockwise direction of rotation, see phase rotation rule. iDFT is also a correlation like DFT as explained earlier with amplitude scaling as .

In words, iDFT equation states that to reconstruct a signal , sum complex sinusoids from to after weighting them with DFT coefficients .

## DFT Periodicity

A natural consequence of DFT equation above is that can be proved to be periodic with period , where periodicity of a signal was defined in article about some signal classifications. Since both and are integers and and are periodic signals,

Similar identities hold for as well. Thus, can be found through DFT definition in Eq 1 as

(3)

It is not surprising that the DFT is a periodic signal in frequency domain because we saw in the article about sampling how a discrete-time signal has a spectrum with infinite replicas spaced at integer multiples of sample rate and we obtained the discrete frequency axis (in the discrete frequency article) by sampling the primary zone from to at equally spaced intervals, as shown in this Eq. Combine it with Eq and it is clear that frequency samples are exactly the same as , or , and so on. As a consequence, DFT of a signal is indeed a periodic signal in frequency domain.

Interestingly, similar trigonometric identities used to find can be utilized to obtain through definition of IDFT (Eq (2)) as

(4)

Although the DFT of any signal can be taken without any regard to periodicity, whether the DFT structure assumes being periodic with a period or not is a matter of debate in DSP community. Some consider it as a logical conclusion of sampling in frequency domain while some others have perfectly reasonable viewpoints of treating it as an aperiodic signal. Either approach is consistent with other insofar as the signal behaviour and interpretation of DFT output is concerned.

Since a common theme of our explanations is simplicity and periodic approach is simpler to follow, Eq (4) will be our guide. All it says is that although we know nothing about what happens with outside the range to , sampling the frequency axis at discrete points from to creates replicas of in time domain, just like sampling in time domain created replicas of its spectrum in frequency domain during sampling. Figure below shows an aperiodic signal and its periodic extension. I personally consider the other approach more intuitive but it involves concepts like convolution and windowing which we have not covered yet and will encounter later.

As long as , the DFT accurately represents the sampled frequency response of the input signal and there is no distortion. Nevertheless, for , the DFT spectrum is no longer its actual sampled frequency domain representation and there will be aliasing in time domain. Obviously, common sense also dictates that taking DFT of a truncated input signal () should produce inaccurate results.

A major implication of this periodic extension is that sequence shifts for DFT purpose actually result in circular shifts. Assume in the above Figure. Then, a right shift of will knock the last sample at position out of the observation window to the new position . Moreover, it will bring the last sample from its previous extension at inside the observation window to . Conceptually, this is nothing but a circular shift within the window as discussed in the post on transforming a signal. This DFT observation window is shown as red dotted lines within to .

## DFT Approximation of the Actual Spectrum

A natural question at this stage is: how well does the DFT — a sampled frequency function of a sampled time domain signal — approximates the underlying Fourier transform — a continuous frequency function of a continuous time domain signal? An initial guess is that it is not much accurate because the continuous Fourier transform is an integral from to while the DFT is a finite sum.

The actual answer is that this approximation is quite well. However, there are two possible sources of error.

[Truncation error] Clearly, any signal that does not have a finite length must be truncated to accommodate finite length of the DFT.

[Aliasing error] According to sampling theorem, the sample rate must be at least twice than the maximum frequency contained in . Aliasing can occur if the signal is not band-limited.

In the article on the concept of frequency, we discussed that every real signal occupies an infinite amount of bandwidth, as a signal cannot be limited in both time and frequency domains. To avoid truncation errors, a signal must be time-limited which makes its spectrum unlimited causing aliasing errors arise. To avoid aliasing errors, a signal must be band-limited with a sufficient sample rate, but such a signal cannot have finite duration causing truncation errors.

For many cases of practical interest, the amount of these errors is tolerable: with a reasonably band-limited signal that means having very small energy outside a certain frequency band, we can make the signal time-limited and sample it with an adequate sampling rate. That makes the DFT a great tool for analyzing real continuous-time signals.

## Fast Fourier Transform (FFT)

A Fast Fourier Transform (FFT) is neither another type of Fourier transform, nor an approximation to the DFT. An FFT is just a faster method of computing the DFT of a signal by exploiting redundancy in DFT equations. In fact, it was FFT that made the Fourier analysis possible for majority of signal processing applications. For example, if FFT of a signal with length takes 1 second on a computing device, the DFT on the same platform will take approximately 28 hours!

It is then no surprise that FFT is described as "the most important numerical algorithm of our lifetime". In this text, we will not derive the exact FFT formulation and instead will use a software routine to compute the FFT when required. In Matlab, for example, the command fft() serves this purpose.