Having covered the Discrete Fourier Transform (DFT) and the concept of phase, 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 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 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.
shown in Figure below, where .
Let and using the identity , we get
where all the other terms in the summation cancel out. Using the same identity as above
Similarly, component can be found from DFT definition,
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
The above Figure displays the magnitude and phase plots for the DFT of a rectangular signal with which in this case are similar to the and plots, respectively. In general, magnitude-phase and 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, plot is more relevant. How a specific value of affects the phase plot is discussed in the concept of phase.
DFT, Frequency Domain Sampling and Leakage
For DFT of a rectangular signal, the equations are given in Eq (3) and Eq (4), and the magnitude-phase equations in Eq (5) and Eq (6). The corresponding figures are drawn in the Figure above with single impulses at bin 0.
The question is: How can such complex equations generate such simple figures? The answer is that it was a special case due to the whole sequence being equal to one. For an and using Eq (6), the rectangular signal can be made symmetric around zero position, as shown in Figure below for , and (which is the same as due to DFT input periodicity in DFT periodicity Eq).
A clear shape of sinc function in terms of is visible in magnitude plot which is sampled at discrete frequencies . Now we can recognize that the plots in this Figure were also sinc functions but sampled at the peak value at bin and at zero crossings for all other bins.
To comprehend the reason why energy appeared in other frequency bins as well, consider that as explained in the article about complex numbers, a complex sinusoid is composed of and as and components, respectively. These and are orthogonal to each other over a complete period, and () of one frequency is also orthogonal to () of other frequencies , provided that are also integers, i.e.,
The DFT finds the contributions of analysis frequencies for for , in an input signal, which are all integer multiples of a fundamental frequency . It is due to this integer multiplicity that DFT is able to find each contribution independently of all others. And if the input signal contains contributions from only these frequencies, the DFT output is proportional to the magnitude at the contributing frequency bins and zero at the remaining bins.
In a real scenario, the input data sequence is not bound to contain energy precisely at a set of given analysis frequency bins. If the input has a signal component at some intermediate frequency between these integer multiples of , say , Eq (7) does not hold and this input signal shows up to some degree in all output bins of our DFT due to unaligned sampling instants in frequency domain. This is known as DFT leakage.
When we perform the DFT on real-world finite-length time sequences, DFT leakage is an unavoidable phenomenon. Let us construct an example to observe this in detail.
Assume a signal with frequency kHz at a sample rate of kHz.
The solid blue curve is shown in Figure above in time domain along with one analysis frequency kHz. Note that both the input frequency and the analysis frequency complete four full cycles during the sampling interval and hence its DFT, plotted in Figure above, has two impulses at bins and with zero input from all the other bins. The shape of the actual curve is the same sinc function but it is sampled in frequency domain at just the right points — integer frequency bins due to integer number of cycles of the input in time domain.
Now let us change the input signal slightly by making the input frequency equal to kHz as shown in Figure below.
Observe in this Figure below that the analysis frequency completes four full cycles during that interval, while the frequency kHz in the original signal does not have integer number of cycles over -sample interval, causing the input energy to leak into all the other DFT output bins. The bin is not zero because the sum of the products of the input sequence and the analysis frequency is no longer zero (same is also true for, say, ). This leakage causes any input signal whose frequency is not exactly at a DFT bin center to leak into all of the other DFT output bins. The shape of the sinc function did not change as compared to a kHz input but it is sampled in frequency domain at non-ideal points — fractional frequency bins due to non-integer number of cycles of the input in time domain.
One final question: an input sinusoid at kHz sampling the sinc function at unaligned points in frequency domain makes sense, but why the graph in this Figure exhibits a similar kind of leakage? The reason is that an all-ones rectangular sequence with can be considered a single complex sinusoid at frequency but its truncated version with , is not. It is actually made up of all sinusoids just like a periodic square wave we encountered in this Figure.
The DFT of a rectangular signal has a mainlobe centered about the point. Its amplitude cannot be found by plugging in in Eq (5) because both the numerator and denominator become zero resulting in undefined expression. Although a mathematical trick (known as L’Hôpital’s rule) can be applied to compute it mathematically, we take an easier course. The peak amplitude of the mainlobe is because at , DFT definition dictates that the DFT is the sum of all original samples due to and . Then, the sum of unity-valued samples is . Consequently, the peak value is seen to be in this Figure and in this Figure.
Mainlobe Width and Zero Crossings
The width of the mainlobe is defined by zero crossings of the curve. Since , the first zero crossing occurs when the numerator argument in Eq (5), , is equal to . All other zero crossings are integer multiples of the first. So the mainlobe width is given by the value of the first zero crossing as
This value is confirmed from in this Figure and in this Figure. A zero crossing right at sample in this Figure illustrates that it was sampled at peak value for bin and at zero for all other bins.
Most of the discussion until now was around the magnitude plots. Let us understand the concept of phase again through the DFT of a rectangular signal. Now the phase plot in this Figure for , and has been drawn in Figure below after unwrapping phase jumps which arose due to changing and signs. The resulting phase is a straight line with a positive slope equal to . Where did this number come from?
We learned in in the article about phase that a time shift of samples results in phase rotation of , the direction of which depends on the direction of time shift. For time traveling in the past (i.e., a signal delay), the phase rotation is also negative while for time traveling in the future (i.e., a signal advance), the phase rotation is also positive.
To complete the picture, we need one extra piece of information that we prove later: the DFT of a real and even symmetric signal is purely real with part. Consequently, its phase is equal to or (depending on the sign of part). In our example, an even symmetric signal would have been obtained for . Then, the phase plot would be or as shown in Figure (part a) below.
However, for , it is a left shift of that even symmetric signal by sample. Thus, plugging in the expression from this Eq gives the phase rotation for each frequency bin as
In this case, was equal to . Starting from , the phase shift can be seen to be from this Figure. For all ,
A linear slope of is thus verified. Part (b) of above Figure shows the phase plot for a right shift of , i.e., . Observe a negative slope of when adjusted for phase jumps.
A General Sinusoid
The DFT of a general sinusoid can be derived similarly by plugging the expression of a complex sinusoid in DFT definition and following the same procedure as in the rectangular sequence example.
Nevertheless, having understood the above concepts, we can see how the magnitude and phase plots of the DFT of a general sinusoid look like by an easier method. As an all-ones rectangular sequence is nothing but a complex sinusoid with frequency with length , the DFT magnitude of a general complex sinusoid with frequency (which can be a non-integer) can be found by putting (as it spans the whole length), (as it starts at ) and instead of in Eq (5) and Eq (6) as
Similarly, the DFT of a real sinusoid can be seen as the sum of the above expression with a similar expression replacing with because each real sinusoid consists of two complex sinusoids scaled by half.
For example, consider a signal shown in Figure below and consisting of two sinusoids at kHz and kHz as
Our DFT analysis frequencies, from this Eq, for an point DFT are
So in this case, bin corresponds to an actual frequency of kHz, bin to kHz, and so on. The DFT can be found by applying DFT definition and is plotted in Figure below.
From magnitude plot of this figure, observe that the DFT has detected two real sinusoids in this signal because the impulses at bins and indicate the presence of two complex sinusoids that combine to form one real sinusoid at a frequency kHz. A similar argument holds for the other frequency of kHz.
DC or Average Value
The DC, or average, value of this signal is which is evident from Eq (9) as the average value of a sinusoid over an integral number of cycles is .
When an input signal contains a complex sinusoid of peak amplitude with an integral number of cycles over input samples, the output magnitude of the DFT for that particular sinusoid is . This can be checked by plugging in the expression for a complex sinusoid into DFT definition. Using Eq (7), the DFT output for a complex sinusoid is given as
Using the identities and ,
Thus, the output magnitude of the DFT is proved as .
For a real sinusoid, is and only the first term in part of the above equation survives. Since , the output magnitude of the DFT for a real sinusoid is .
Considering the fact that is composed of two real sine waves with amplitudes and , we can see in this Figure that kHz sine wave has a magnitude and kHz sine wave has a magnitude .
But if the sinusoid in a rectangular signal is real with frequency , why is the peak value in the magnitude plot in this Figure equal to rather than ? This is because the DFT of a regular real sinusoid is two impulses with amplitude , one at that frequency and the other at its negative counterpart, but at frequency , both of these impulses merge together to give a magnitude of . Another way to understand it is that an all-ones sequence is actually a complex sinusoid at frequency because it has an all-ones sequence in part and all-zeros sequence in part.
Referring to the phase plot and going back to the DFT definition, assume that the input is . The DFT output is given as
for an arbitrary number and orthogonality of and over a complete period. The phase is for positive and for negative . Therefore, a phase at a particular frequency is with respect to a cosine wave at that same frequency.
In this Figure, bin frequency at kHz has a phase of . Is it a cosine with a phase of ? From the identity , it is indeed a sine waveform with an initial phase of which can be confirmed from the first term of in Eq (9). The corresponding phase at bin is obviously , see this Figure.
As for the second term , it is a sine at kHz with a phase shift of , or a cosine with a phase of as shown in this Figure for bin .
Notice in this Figure how the signal is composed of two sinusoids at and kHz, respectively, where former is a cosine with a phase of (or a sine with ) and the latter is a cosine with a phase of (or a sine with ). Now referring to its time domain plot in this Figure, the first sinusoid is positioned around the origin according to its cosine (or sine) phase, while the second sinusoid is positioned around the origin according to its cosine (or sine) phase. Through the phase plot, the DFT in fact finds the time alignments of all the sinusoids at bin frequencies .
Sometimes it is easy to get confused from the fact that component of is in the above example, leading to an incorrect phase result of or . However, as illustrated in this Figure, we have to differentiate -plane of time domain from -plane of frequency domain. The component here is in time domain only but the phase plot is determined by components in frequency domain. There, a real sinusoid is a sum of two complex sinusoids and the phase of those two complex sinusoids in frequency -plane determines the starting sample of the real sinusoid in time domain.
Do remember that the plots shown in this Figure are — once again — sinc functions overlapping each other. However, since the signal consists of two exact analysis frequencies, the frequency domain is sampled at the precise locations of zero crossings. That being the case, the sinc function becomes invisible and looks like two sets of impulses only.
The Unit Impulse
Having known the DFT of a rectangular signal, we have two ways to find the Fourier transform of a unit impulse.
[Time-Frequency Duality] A closer look at DFT and iDFT equations reveal that the forward and inverse transform are almost identical, except the scaling factor and direction of rotations of analysis sinusoids. Therefore, time and frequency domains are dual and DFT of a signal in time domain can be derived by the iDFT of a signal in frequency domain. For example, a single impulse at frequency bin in this Figure is an all-ones rectangular sequence in time domain. By duality, the inverse is also true: a single impulse in time domain corresponds to an all-ones rectangular sequence in frequency domain.
[Rectangular signal] From a general rectangular sequence as in this Figure, it is evident that a unit impulse is also a rectangular sequence with length . Therefore,
Since the starting sample , the angle is equal to . This DFT was graphically illustrated in this Figure.
The Sampling Sequence
The sampling sequence is a sequence of unit impulses repeating with a period within our observation window (and owing to DFT input periodicity, outside the observation window as well). Figure below illustrates the sampling sequence in time domain for and .
To compute its DFT, consider that and . Then,
Since except when , we can write where . We are assuming as an integer here because otherwise will not be periodic. So in the above example, for non-zero values of at and .
Note that the above equation is very similar to Eq (2) encountered while computing the DFT of a rectangular sequence. Therefore, substituting both the length of the sequence and observation window equal to in Eq (5) and doing the same for part, we get
Magnitude and Phase
The sequence is plotted in frequency domain in Figure below, where both and components are shown for and . Since the sequence is aligned in time such that it is symmetric with respect to zero, the phase is zero in frequency domain. So the magnitude plot is the same as the part.
In the DFT of a rectangular signal, we saw that both the numerator and denominator become equal to zero for . In that case, the peak of the mainlobe was equal to , the length of the sequence. We found this value by plugging in the DFT definition and deduced that the result is just a sum of all time domain samples because and . Here in this case, the peak value can easily be seen as the sum of unit impulses and hence equal to .
Remember from DFT of a general sinusoid derived above that the DFT of a complex sinusoid with amplitude in time has a magnitude in frequency domain. Here, the spectral replicas have a peak magnitude of instead of which suggests that the actual spectrum has been scaled down by a factor of . This is shown in Figure above.
There are multiple impulses in frequency domain here: more than one as in DFT of an all-ones rectangular sequence but less than as in the DFT of a unit impulse. Observe from Eq (11) that when the denominator is non-zero, the spectrum is clearly zero. When both the numerator and denominator are zero, the peak values are as above. To find these locations, check where the denominator is an integer multiple of as well.
In our example, these peaks turn out to be and as shown in Figure above. If you guessed that these impulses in frequency domain are actually sinc functions sampled at just the peak and zero values, you are right (compute a length- DFT of this sequence instead of length-, for example).
Finally, later in another post, we will summarize some important properties of the DFT in a table. In that table, one of the most important properties of DFT we use over and over again is the Parseval’s relation that relates the energy of a signal in time domain with the same in frequency domain.
In words, energy of a signal in time domain is equal to its energy in frequency domain scaled by . The intuitive reason for this scaling factor in frequency domain is that as discussed above, the DFT output for a complex sinusoid with amplitude is , an time magnification.