51
Chapter 6 - Discrete Fourier Transform (DFT) ComplexToReal.com Page 1 6 Discrete Fourier Transform In Chapter 5, we discussed the Fourier transform of discrete signals, called DTFT, for aperiodic and periodic signals. The DTFT is a theoretical concept. It is not user-friendly, and it requires integration, something which neither we nor our computers do well. DTFT hence is primarily an educational tool that we use as a model for a related tool that better fits our need of machine-based algorithms. In this chapter we move from theory to reality. We discuss the modification of DTFT which allows us to do Fourier transform of finite length signals. The result, we note happily is a spectrum that is discrete, something which we consider very desirable.In Fig. 6.1, we look at the progression of the tools based on Fourier Theory to the topic of this chapter the Discrete-time Fourier Transfrom (DFT). Figure 6.1 – Development of Fourier transform from Fourier series

Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

  • Upload
    vanliem

  • View
    243

  • Download
    4

Embed Size (px)

Citation preview

Page 1: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 1

6

Discrete Fourier Transform

In Chapter 5, we discussed the Fourier transform of discrete signals, called DTFT, for

aperiodic and periodic signals. The DTFT is a theoretical concept. It is not user-friendly,

and it requires integration, something which neither we nor our computers do well. DTFT

hence is primarily an educational tool that we use as a model for a related tool that better

fits our need of machine-based algorithms. In this chapter we move from theory to

reality. We discuss the modification of DTFT which allows us to do Fourier transform of

finite length signals. The result, we note happily is a spectrum that is discrete, something

which we consider very desirable.In Fig. 6.1, we look at the progression of the tools

based on Fourier Theory to the topic of this chapter the Discrete-time Fourier Transfrom

(DFT).

Figure 6.1 – Development of Fourier transform from Fourier series

Page 2: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 2

Path to DFT

Discrete Fourier Transform (DFT) borrows elements from both the discrete Fourier series

and the Fourier transform. It comes to us directly from the DTFT for periodic signals

using the coefficients computed by the DTFS. It could have had a better name such as

Finite-time Fourier Transform (FTFT), but even that is confusing. So we are stuck with

this term, where it is not clear why the T has been dropped. DFT is name we have.

This similar sounding variation of the DTFT, DFT is the most important and most used

of all signal processing tools. It is the culmination of all the mathematical tools we have

been looking at in this book, from the Fourier series to the discrete-time Fourier

transform. It is a practical algorithm such that it can be implemented in software and

hardware and allows signal processing at fast speeds.

Let’s review the path we took to get to the DFT.

Case 1 – Continuous-time Fourier Series (CTFS)

The input signal is periodic with period 0 T and signal is continuous in time. CTFS gives

us a discrete frequency spectrum which we like. We called the spectrum values by the

term kC , the Fourier series coefficients, where this term is the complex amplitude of the

kth harmonic.

Case 2 - Continuous-time Fourier Transform (CTFT)

Here we apply the Fourier series concepts to an aperiodic signal. We let the period go to

infinity. This ostensibly makes the signal periodic. CTFT gave us a discrete frequency

spectrum, which we also like. But continuous time is still a problem and we want to

avoid dealing with it. We refer to the spectrum by the term ( )X where this term is the

complex amplitude of the kth harmonic.

Case 3 – Discrete-time Fourier Series (DTFS)

Then we sample the signal, get a discrete version of the signal and calculate the discrete-

time Fourier series (DTFS) coefficients. The DTFS coefficients give a discrete

frequency spectrum but unfortunately the spectrum replicates endlessly. We referred to

the spectrum values by the term kC where this term is the complex amplitude of the kth

harmonic.

Case 4 – Discrete-time Fourier Transform (DTFT)

By letting the period go to infinity, we get the discrete-time Fourier transform (DTFT).

This gives us a continuous frequency spectrum, which is not desirable. But we notice that

if take the DTFT of a periodic signal, which has the effect of limiting the signal to a time

Page 3: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 3

window, the spectrum becomes discrete. This takes us to Discrete Fourier Transform

(DFT), our true quarry and the topic of this chapter.

Table I – Properties of Fourier transform input and output signals

Input is Output Spectrum is

Periodic Time

Resolution

Periodic Frequency

Resolution

Fourier Series

Continuous CT-FS

Periodic Continuous No Discrete

Fourier Series

Discrete

DT-FS

Periodic Discrete Periodic Discrete

Fourier Transform

CTFT

Non-periodic Continuous Non-

periodic

Continuous

Fourier Transform

DTFT

Non-periodic Discrete Periodic Continuous

Discrete Fourier

Transform

DFT

Non-periodic Discrete Periodic Discrete

The DTFT which we covered in Chapter 5 is used to assess the spectral content of

discrete signals, aperiodic or otherwise, however it falls short of an ideal analysis tool.

Yes, it applies to discrete time signals and it also applies to aperiodic signals. But the rub

is that the DTFT or the spectrum of an aperiodic discrete signal is continuous. This is

very annoying. However, we noted in Chapter 5, that when doing the DTFT of a periodic

signal, the spectrum is not continuous but is instead discrete. This discovery leads us to

the development of the Discrete Fourier Transform (DFT) which makes all our data

dreams come discretely true.

The Discrete Fourier transform (DFT)

The DFT has a few really great properties.

1. We can do a DFT of any length signal.

2. We don’t really need to know the period of the signal.

3. DFT is easy to do in software.

4. DFT is discrete.

Page 4: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 4

The DFT as we shall see through examples, is not some second-rate estimate of the real

thing but is an exact sampling of the actual DTFT at uniformly spaced frequencies. The

signal itself can be either periodic or aperiodic, the DFT will give valid results for both.

So you can think of it as a DTFT with a coarser resolution. Conversely, a DFT with fine

resolution takes us backwards and gives us a pretty good idea of the DTFT.

In Eq. (6.1), we reconsider the expression for DTFT. The frequency is the digital

frequency. It is considered continuous because n the time index, spans infinity. The

signal [ ]x n itself is discrete however. Hence the DTFT is a continuous function.

[ ] j n

n

X x n e (6.1)

Frequency resolution question

We learned in Chapter 5 that DTFT frequency resolution (measured in radians per

sample) is continuous, but its uniqueness is limited to the range . For DFT,

we want to make this equation fit a finite length signal. To change the resolution from

infinite to finite, instead of allowing the frequency an infinite precision, we in essence are

computing the DTFT only at a certain frequencies. Let’s call the number of frequencies

we pick, N. What is this N? This is the number of samples per period. And where do we

get the period? Well, this is where we do a bit of hand waving. We say, we don’t really

know, so we will take all the samples collected and call that the period. Hence N is the

total number of samples collected and is akin to the period of the signal.

We divide 2 by this N and this becomes our fundamental frequency, same as in DTFS.

This can be considered the frequency resolution. The integer multiples of this frequency

become the N harmonics of the fundamental as given by Eq. (6.2) These N frequencies

are a finite basis set for the DFT, a concept exactly the same as we covered for discrete

Fourier series in Chapter 3.We evaluate the DTFT only at these N frequencies instead of

an infinite number of frequencies as we do by integration for the DTFT. We write the

fundamental and the harmonics frequencies as

Fundamental frequency 0

20k

N

(6.1)

Each harmonic frequency 2

0,1, 1k

kk N

N (6.2)

The index k is the harmonic index and ranges from 0 to N-1, for a total count of N.

The units of this frequency are radians per samples. DFT as opposed to DTFT, is function

of the total number of points we use for the analysis. The term N can be the number of

Page 5: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 5

points collected/used for the analysis or it can be even larger than the number collected,

through a process called zero-padding. Clearly larger the N, the smaller the frequency

resolution, which is a good thing.

The term Frequency resolution can also be written as in Eq. (6.3) in terms of the

sampling frequency. Here Fs is the sampling frequency in samples per second, or Hz.

These two terms, Fs and N are independent. Normally when we see discrete samples

plotted such as in Fig. 6.2(a), we do not see the sampling frequency. The x-axis is often

in terms of sample numbers.

ss

FR

N (6.3)

What the DFT thinks

We are dealing with reality now and we have just collected a bunch of samples. We plot

out samples as in Fig. 6.2(a). We hand these to the DFT for some sort of analysis. The

DFT by its nature, thinks that the points we have offered it are coming from a periodic

signal. It thinks that even though it we have given only a limited number of samples, they

actually come from a big signal with infinite cycles of data, as in Fig. 6.2(b) and (d). It

doesn’t know the truth. It has no idea that we are fooling it, and that we actually have no

idea what is outside of what we have collected. Periodic? We don’t know. Probably not.

If there are zeros in the samples collected, it thinks that they also are part of the cycle. If

the data has repeating patterns of pulses, it thinks they also repeat somewhere in the

signal heaven. The whole of the samples collected are presumed to be one period and

hence the length of the signal becomes the period of this presumed periodic signal. The N

samples offered to the DFT machine are all considered part of one basic cycle by the

DFT. The value of N for a DFT is the length of the signal and not the non-zero data

points. The length of the signal for the first case in Fig. 6.1(a) is 10 samples and includes

the two zeros on each side. The length of the signal in (b) is 17 samples. The DFT

analysis is always limited to N samples but we have to keep in our mind the picture in (d)

that the DFT is thinking it has.

Page 6: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 6

Figure 6.2 - The signal of interest is any number of samples collected including the

zeros as in (a) and (c). DFT presumes the collected piece is one period of a periodic

signal, as shown in (b) and (d).

DFT from DTFT

DFT applies to discrete signals which may be periodic or aperiodic but are of a finite

duration. DFT is very similar to both DTFS and DTFT. The differences between the DFT,

DTFT and DTFS are subtle. Unfortunately the name DFT is also confusingly similar to

DTFT. So first let’s again look at the definition of DTFT.

[ ] j n

n

X x n e (6.4)

DTFT is specified by the notation X , and the parentheses around the frequency imply

that is it a continuous function of frequency. On the right side of Eq. (6.4), input signal

[ ]x n however is discrete (note the square brackets). The index n, represents a fixed

amount of time between each sample, called sampling time,   sT . The signal is presumed

infinitely long, so the index n extends from to . DTFT requires an impossibly

huge number of products and sums. But if we cut the length to a finite number of

samples, amazingly enough, we solve many problems. It turns the integration into a sum,

which a computer can do with ease.

Page 7: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 7

Figure 6.3 – Comparing DTFT with DFT

Take the aperiodic signal in (a), its DTFT in (b) is continuous and repeating, in (c) we take the iDTFT of this signal, we get a discrete but

periodic version of signal. In (d) we take the DFT of this signal in (c) over

one period of N samples, and get the sampled version of the DTFT in (d).

In Fig 6.3(a) we see a little signal of length N = 7 points. The piece shown is all we have.

If we compute the DTFT of this aperiodic signal, we get the plot on the right in (b). The

spectrum is continuous and repeats as we learned in Chapter 4. Now we compute the

iDTFT of this signal and we get the DTFT’s version of the result in (c), which is a

periodic discrete signal. That tells us what the DTFT is thinking. Although we gave it

“one” period of data, it is giving us back the periodic version of it. When we do the DFT

of this periodic signal in (c), we get the discrete version of the spectrum in (b). The DFT

in (d) is periodic but discrete. The adjacent copies maybe ignored for computation

purposes, but they are real, and must be filtered out in reality. In Fig 6.3(d), we also see

the DTFT plotted in a dotted line. The DFT points are the discrete samples of the DTFT

shown. It may seem that it is an approximation of the DTFT, but actually the DFT is not

an estimate but an accurate sample of the DTFT at the selected N points. DFT is often

called a N-point sampled version of the DTFT. How N, the number of samples is

selected is important and has many consequences as we shall discuss in this chapter.

Page 8: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 8

DFT as a sampled version of the DTFT

Let’s assume that we have a finite length signal x[n] that exists only within

0 1n N points. We don’t know anything about this signal outside of the N

samples. Oh yes, and also we see no particular periodicity in the samples collected. If

( )X is the DTFT of this signal, then we can obtain N samples of the DTFT (which has

an infinite number of points) by sampling the DTFT at N uniformly spaced frequencies.

Note that ( )X ranges from 0 2 . Hence we write a sampled version of DTFT

(soon to be called DFT) as

02

[ ] ( ) ( )k

X k X X k XN

(6.5)

Where [ ]X k are the N samples of the DTFT ( ).X That is, if we know the continuous

DTFT, we can just sample it and voila, we have the DFT.

Using this discrete definition of frequency, and inserting it into Eq. (6.4), we can get the

DFT form of the DTFT. So here is main idea: DFT is a sampled form of DTFT. So here

is our definition of the forward DFT of a discrete “piece” of a signal. Note we refer to

DFT by [k]X whereas DTFT was written as ( )X .

21

0

[k] [ ]k

N

Nj n

n

X x n e (6.6)

There are total of N terms in this calculation from the N samples collected. In DFT, k

is referred to as the bin number, a name by which we imagine a bucket in which we

are collecting the harmonic frequencies. In fact the term 2

[ ]X k is considered the total

energy in the kth bin and is used to develop the energy or power spectrum of the signal

directly from the DFT. Note that the term bin is used only in frequency domain. Time

samples are never called bins.

Page 9: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 9

There are three ways the x-axis of a DFT can be numbered.

Figure 6.4 – What the x-axis of a DFT means

The first way to refer to it is by the digital frequency. No matter how many samples we

have, the range of DFT in terms of the digital frequency is always 2 . That’s because we

are dealing with discrete samples. If the spectrum (DFT) is centered at 0, then the

boundaries are . If there are N data points, then each tick mark (bin) differs from

the next by 2 N radians.

The second way is to plot the DFT as a direct function of the bin number, k. If there are

N samples, then k ranges from 0 to N-1, or more often from –N/2 to N/2.

The third form is in terms of the sampling frequency. If the sampling frequency of the

signal is Fs samples per second, or Hz, then we can presume that that signal does not

contain any frequencies higher than that. Hence the range of the DFT is 0 to Fs or –Fs/2

to +Fs/2 Hz. Each value of k is equivalent to ksN F Hz frequency change or bin size. Hence

at extremities, we have k = 2sFN

N , we get f = Fs/2. In many software packages, the range is

often given just as -1/2 to +1/2 by setting Fs = 1. This is to make the range independent of

the sampling frequency.

What happens when we sample is we are limiting the signal spectral components to

exactly the range, 2 2s sF to F . All other frequencies are no longer “visible”

because that is the width of our spectral window. However no signal are ever denied their

place in a spectrum, higher frequencies if they are there, will fold back into this window

as ghosts. And the only way not to have that happen it to first filter the signal, with an

anti-alias filter and actually banish these higher frequencies so they can not fold back.

Hence unless the signal is filtered before sampling, we will get aliasing. Most signals

have wideband noise and spurious high frequency signals, and unless we apply an anti-

aliasing filter, these will fold back into the signal spectrum.

Page 10: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 10

The inverse DFT is given by

21

0

1[n] [ ]

kN

Nj n

k

x X k eN

iDFT (6.7)

The indexes k and n are confusing. Some books use them in the reverse fashion, with n

the harmonic index and k the time index. The thing to remember is that they are both

equal in length to N. If we have N time samples, then they are referred to by n as the time

index. Out of the forward DFT [ ]X k , we get N harmonics, even though we refer to the

individual harmonics with index, k. But there are only N total harmonics. Since the range

of both indexes is N, the confusion often may still get you the correct answer! So be on

watch.

The difference between the DFT and its inverse, iDFT is just a scaling term in the front

of the iDFT 1 ,N and a change of sign of the exponent. Both of these are easy to

understand. The normalization by N takes the N additions and then normalizes it, so DFT

just as the DTFT is a measure of relative magnitudes only. The change in sign of the

exponentiation is just reversing the harmonics. The two expressions are very similar and

this makes the hardware/software implementation of DFT algorithm easy. You can easily

do it in Matlab with just a few lines of code, like this.

x1 = [ 2 1 -3 4]

N = length(x1);

nf = -N/2: N/2-1

mag = fftshift(abs(fft(x1, N)));

phase = atan(imag(fft(x1, N))/real(fft(x1, N)))

Ichan = fftshift(real(fft(x1, N)));

Qchan = fftshift(imag(fft(x1, N)));

Note that we can plot the result either as magnitude and phase or as I and Q channels per

this Matlab code. In Matlab, the DFT command is implemented by a command called

“fft”. The term “abs” in front of the fft command gives us the magnitude of the DFT, not

power. The fftshift command centers the DFT on zero, a preferred from of showing the

DFT. The DFT is usually drawn as a stem plot in Matlab. However, if N is large, a stem

plot becomes a solid blob. The DFT in such cases is drawn with the “plot” function

showing the envelope instead. But that is just convention of drawing and does not change

the underlying nature of the DFT that it is defined only at discrete points.

Page 11: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 11

Computing DFT

Example 6-1 Compute the DFT of this signal given by the following four samples.

[ ] [2 1 3 4]x n

N, the length of the signal is 4, hence the fundamental frequency is equal to 2 4 2 .

Using Eq. (6.6), we write the DFT as

2

2 2 2

1

0

1 2 3

[ ] [ ]

2 3 4

kN

Nj n

n

j k j k j k

X k x n e

e e e

From here we can compute the first two terms as

2 2 2

1 2 3

[0] 2 1 3 4 4

[1] 2 3 4

2 3 4

5 3

j j j

X

X e e e

j j

j

Computing the other two we find the DFT given by table I and as plotted in Fig. 6.5(a).

Table I – DFT values of the example signal

Index, k I Q Mag Phase

0 4 0 4 1 04

tan 0

1 5 3 5.83 1 35

tan .54

2 -6 0 6 1 06

tan

3 5 -3 5.83 1 35

tan .54

Page 12: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 12

Figure 6.5 – (a) and (b) The real and imaginary parts of the DFT, as well

as (c) the Magnitude and (d) the phase.

So here is our DFT in all its variations. But since this is a 4 point sequence, we get just

four values of the DFT, [k].X It is hard to make sense of what is going on when there are

so few values. We should plot them against the DTFT to see what if anything we get out

of these four values. Where to get the DTFT? In this case it is pretty simple. We use Eq.

6.1.

3

0

1 2 3

[ ]

[ ]

(2 3 4 )

j n

n

j n

n

j j j

X x n e

x n e

e e e

Now we plot the continuous DTFT along with four computed points of the DFT and we

see where these points are coming from. First thing to note, the DFT points are exactly

the correct samples of the DTFT.

Figure 6.6 – The phase and the magnitude of the signal when seen along with the DTFT as its sample points.

Page 13: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 13

We can see from this picture that the four discrete points of our computed DFT although

accurate, missed the highs of the magnitude as well as the lows of the phase. Since

discrete points is all we see in DFT, we need more points to see the underlying spectrum

fully. But here is a problem, if we are given the sequence x[n] which consists of just 4

points and no more data can be had, what can we do with just these 4 points?

Adding zeros to improve the resolution

There is something magical we can do at this point and it is called zero-padding. This is

about the most “fun” you can have in DSP for nothing. It’s a very valuable tool. We add

a bunch of zeros to the end of the signal, x[n] to lengthen it artificially. Now we redo the

DFT for this zero-padded and hence lengthened signal (N + added zeros). Remember we

said that DFT counts the zeros at the ends of a signal as real data. But what is truly

amazing is what we can extract from these zeros. In Fig. 6.7, we see the result of this

zero-padding. The signal x[n] is zero-padded with 12 zeros at the end to make it a 16

point signal. Because we count these new points as part of the period, N is now 16

samples. Its DFT in Fig. 6.7 now has a frequency resolution of 2 16 instead of 2 4 it

had for the 4-point DFT. And of course we get 16 sampled data points of the DTFT

instead of the 4. This looks quite good.

Figure 6.7 – Zero-padding increases N and hence provides more sampling

of the DTFT.

This truly is an amazing result and you should pause to enjoy this moment. Many

metaphors come to mind but all fail to describe the true beauty of this effect. We can say

that the effect of N, the number of samples is like looking at a DTFT through a fence,

with each fence board of width which is inversely proportional to N. A small N is like a

wide board and hides more of the signal. A large N, results in a narrow fence board and

we can see more of the hidden signal. When N is infinite such as the case of a DTFT,

there is no obscuring fence at all. Note that changing N by zero-padding cannot change

the signal hidden behind the fence, it only allows you to see more of it. The only way to

change the DTFT behind the fence is to collect more sample points and do a better

DTFT, or find ways improve the signal behind the fence itself. DFT has no effect on the

DTFT, it is a snapshot of the real thing through an observation “filter”.

Page 14: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 14

Figure 6.8 – DFT is a fence in front of the DTFT. Narrower boards, i.e.

larger N allow us to see more of the real signal.

When we do an N-point DFT, the points in frequency domain are located at sF N Hz

apart. The larger the N, or the number of samples in the signal, the smaller the resolution

and better looking plot we get. Hence if we wish not to miss any highs and lows, we must

select a large enough N either by zero-padding or by more data collection. In essence we

want the N to get as large as we can manage with our devices.

Deriving the DTFT from DFT

Because N is finite, DFT is easy to do using computer. If we want to compute the DTFT

of the signal, then either we can do a longer (much longer) DFT of the same signal or this

being a textbook, we can use math. If you are opposed to this idea then just skip to the

next section.

Since DFT is the samples of the DTFT, we can drive the DTFT directly from the DFT by

interpolation. Given an N-point DFT, we can drive the DTFT by first converting it to a

time domain sequence as we do here. In first row we replace the time domain signal by

its iDFT representation from Eq. (6.7).

1 1 12 /

0 0 0

1 12 /

0 0

1( ) [ ] X[ ]

1X[ ]

N N Nj n j kn N j n

n n k

N Nj kn N j n

k n

X x n e k e eN

k e eN

The underlined term can be written as

Page 15: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 15

( 2 )1( 2 / )

( 2 / )0

( 2 / )( 1)/2)

1

1

sin ( 2 ) / 2

sin(( 2 ) / 2 )

j N kNj k N n

j k Nn

j k N N

ee

e

N ke

N k N

Hence the DTFT can be computed from a finite length DFT X[k] by this expression.

1

( 2 )/( 1)/2 )

0lim

sin ( 2 ) / 21( ) [k]

sin(( 2 ) / 2 )

Nj N k N N

kEffect of time it

N kX X e

N N k N (6.8)

The underlined part of this expression is the result of the time-limit on the signal. This is

coming from the truncation by a rectangular function, the frequency response of which

you see here. This effect of muddying the result by this “quotient” is called Windowing

and we devote a whole chapter to it. The result in Eq. (6.9) is a sum of scaled

exponentials based on the DFT values. This is a true continuous function. If a fast

estimate is needed of the DTFT, the quickest method is to take the time-domain sequence

of size N samples and then zero-pad it to a much longer length M, which is to add a (M-

N-1) zeros to it. The DFT of this new signal which has a finer frequency resolution of

2 / M is often an efficient method of estimating the DTFT, unless of course you can look

up the answer in the back of the book!

3(4 2 )/(3)/8)

0

[ ] [4 5.83 6 5.83]

sin (4 2 ) / 21( ) [k]

4 sin((4 2 ) / 8)

j k

k

X k

kX X e

k

The DTFT we computed for Ex. 6.1 can be derived by applying Eq. (6.8) to the

computed DFT points. Then we can compute a DTFT with as many points as we want.

However, this is sort of going backwards. A DFT if it is of proper length N, is quite good

enough, just as a drawing of a sine wave even though only at a limited number of points

is good enough to discern its main characteristics.

Matrix method for computing DFT

In chapter 5, we calculated DTFT by closed form analysis but we can’t always relay on

our ability to do integrals. The DTFT of arbitrary signals is a difficult task not one we

want to do on paper. DFT on the other hand, has a reasonably easy to understand

architecture. It can be implemented as a linear device as shown in Fig. 6.9 with N inputs

and N outputs. It is completely lossless and bidirectional. N numbers go in and N

numbers come out, and using only addition and multiplication.

Page 16: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 16

We can view the DFT as a linear input/output processor consisting of N equations.

Assume we have an N-length processor. We have collected L data symbols. If N is less

than L, then we select N samples out of the L and perform the DFT calculations on these

N points. If N is larger than the L collected samples, then we have to do something to

increase the number of samples from L to N. Some algorithms of the DFT will

automatically zero-pad a time domain signal to make the length equal to N.

Figure 6.9 - Architecture of a forward DFT Processor

We can build the DFT calculating machine in two parts, one for the forward or the DFT

and the other for the Inverse of the DFT or iDFT. We feed N time-domain samples into

the DFT machine in Fig. 6.9(a). The device needs all N points simultaneously before

anything can happen. This is because each sample makes a contribution to the each of the

outputs, the harmonic components [ ]X k . N samples go in and N samples of frequency

response, [ ]X k come out. Each X[k] gets a little contribution from each x[n].

Here we write out each equation.

2( 1)42

2( 1) 4( 1) 2( 1)( 1)

[0] [0] [1] [2] [ 1]

[1] [0] [1] [2] [ 1]

[N 1] [0] [1] [2] [ 1]

NN N N

n N N NN N N

j j j

j j j

X x x x x N

X x x e x e x N e

X x x e x e x N e

(6.9)

The matrix computation done this way requires a number of calculations that are

proportional to 2.N If we take advantage of the symmetry as well the phase relationship

of the sine and cosine, the number of computations can come down to a number more

like 2logN N . This and other algorithmic innovations were first proposed by J.W.

Cooley and John Tukey in1965. There are now many variations on their original invention

and they are all referred to as the Fast Fourier transform or FFT. Their innovation was

very important for hardware implementation. FFTs are what we use today for calculating

the DFT, so much so that we often find ourselves saying “take a FFT” when we mean the

DFT.

Page 17: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 17

To make the computations simpler, we first simplify a small piece of it. We notice that

all calculations require the manipulation of the complex exponential. The complex

exponential is hard to type, so we simplify it by writing it like this.

2 /j N

Ne W

We also introduced this idea in Chapter 3, when discussing the discrete Fourier series

calculations. It is easy to see that NW is function of N only, the rest of the terms are all

constants. Now also define the same constant in terms of two more variables, n and k.

These are our time and harmonic indexes.

2 / 2 /nknk j N j n k NNW e e

This form has the variables n and k in the exponent and so the constant NW is written

with all three indexes as nkNW . Here we are merely raising NW to power nk, or

nk

NW .

Hence nkNW is a matrix of size n k with each index ranging from 0 to (N-1). Now

rewrite DFT using the term, .nk

NW This is somewhat easier to write than the exponential,

as it has less moving parts.

1

0

[ ] [n]N

nkN

n

X k x W (6.10)

Now we write Eq. (6.10) in matrix form as

nkNWX x (6.11)

X is the output Fourier transform vector of size N and x is the input vector of the same

size.

(0) [0]

(1) [1]

( 1) [ 1]

X x

X x

X N x N

X x

The nkNW term in Eq. (6.11) is called the DFT matrix and is written for all n and k indices

as

Page 18: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 18

2 ( 1)

2 4 2( 1)

( 1) 2( 1) N( 1)

1 1 1 1

1

1

1

NN N N

nk NN N N N

N N NN N N n k

W W W

W W W W

W W W

(6.12)

Note that the matrix size is n k , but since both n and k are equal to N, the DFT matrix

size is equal to N N , hence this matrix is always square. The columns represent the

index k of the harmonics and rows the index n, time. The first row has index n = 0, so all

the first row terms are equal to 1, because 0 ( 0) 1

n k j nNW e .

The first column has index k = 0, hence all nkNW terms in the first column have a

zero exponent and so all are also equal to 1. The third row, second term is equal

to 2NW . For k =1 and n =2. The rest can be understood the same way. Note that the

matrix is symmetrical about the right diagonal such that

nk knN NW W

All of the terms of Eq. (6.12) are constant for given n and k integers. If you stare at the

equation long enough, I am sure just as Cooley and Tukey, you will be able to see the

advantage of matrix calculations. This matrix can be pre-computed and stored for various

value of N. That saves computation time. We don’t need to compute the whole matrix as

well, because it is symmetrical. There are actually a lot of tricks that can be used to make

computations efficient. We can also show that the inverse of this matrix is easy to

compute because it is just the inverse of the individual terms. This also makes reverse

computation easier and quicker.

1 *1nk kn

N NW WN

(6.13)

Let’s write out the DFT matrix for N = 4. The fundamental frequency for N = 4 sample

signal is equal to 024 2

. Hence we write 2

4

4

kj nnkW e .

This is equal in Euler form to

2

2cos( )j nk

e nk 2jsin( )

nk

nk

j

Page 19: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 19

Product nk is always an integer, hence the cosine term for this case is always zero. The

sine however is non-zero and depends on the specific value of product, nk . So

depending on the values of the product, we get these values for the matrix entries.

04

14

24

34

0, 1, 1

1, 1,

2, 1, 1

3, 1,

n k W

n k W j

n k W

n k W j

From this we can develop the 4nkW matrix as

0 0 0 04 4 4 4

0 1 2 34 4 4 4

4 0 2 4 64 4 4 4

0 3 6 94 4 4 4

1 1 1 1

1 1

1 1 1 1

1 1

W W W W

j jW W W WW

W W W W

j jW W W W

(6.14)

The inverse comes easily from Eq. (6.9)

4

1 1 1 1

1 1

1 1 1 1

1 1

nk j jW

j j

(6.15)

Notice from (6.14) and (6.15) that only the imaginary components changed sign. All the

real terms kept their sign. Some values of the matrix are complex conjugates pairs so we

don’t even need to calculate them saving time. This is of course related to that fact that

for the forward transform we need 0jn ke and for the reverse we need 0jn ke . The

difference between these is that the imaginary part changes sign. cos sinj vs. the

cos sinj .

So in (6.15) for the inverse you are seeing the imaginary part changing sign but not the

real part.

We can now use this DFT matrix to calculate the DFT of any arbitrary signal of 4 input

points using the equation (6.6). Larger DFT matrices would be needed to compute larger

size DFT. What is nice is that these matrices (of any given size) are always the same and

can be pre-computed and kept in memory to speedup calculation.

Page 20: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 20

For the computation of the DFTs we will use the algorithm built-in to Matlab. It allows

us to compute an N-point DFT for any N, as long as it is an integer, although this

function is called FFT. Most FFT algorithms use signal lengths that must be powers of 2.

Computing a DFT using the matrix method

Now we will compute the DFT of an aperiodic signal from Ex. 6.1 by the matrix method.

[ ] [2 1 3 4]X k

We already computed the 4 point DFT of this signal in Ex. 6.1. The values computed

were

[ ] [4 5.83 6 5.83]X k

Now we will use the matrix method for the solution to see if we get the same thing.

We write the matrix equation using the DFT matrix for N = 4.

Okay, we got the same thing!

Now let’s compute the inverse DFT.

1

[ ] [ ]NX k W x n

Here we will use the matrix we developed for the inverse DFT.

1 1 [0] [0] 1 1

1 [1] 1 [1]

[2] 1 1 1 1 [2]

[3] 1 [3] 1

x X

j X x j

X x

x X j j

Page 21: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 21

We got the original values back. This is exactly what happens inside Matlab when asked

to execute the FFT/iFFT function.

Example 6.2

Find the DFT of [ ] 2 [ 1] 3 [ 2] 5 [ 4]x n n n n

This signal can be converted to 5 samples as follows; [0, 2, 3, 0, 5]x

For N = 5, the fundamental frequency is equal to 0

2

5 .

From Eq. (6.8), we compute the DFT by

25

2 6 105 5 5

4

0

[ ]

2 3 5

k

k k k

j n

n

j j j

X k x n e

e e e

The DTFT similarly can be written as

0 0 0

1

0

2 3 5

[ ]

2 3 5

Nj n

n

j j j

X x n e

e e e

We can calculate the five values easily for each k, by summing for n from 0 to 4. In Fig.

6.6(a) we plot the signal and its five values. The plot in (b) shows the 5 computed values

for X[k]. Since we have such few data points, the plot does not make sense, until we plot

the data along with the DTFT (as from example Chapter 5). Plotted against the DTFT, we

see that they are indeed the true values of the DTFT at the selected points. The sampling

is not that great, it misses some of the high points.

Page 22: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 22

We said that the DFT is the true sampled value of the DTFT, this statement is true but its

effects is not always what we want. If a signal is truncated in such a manner that the

periodicity is violated, the DFT values computed will not be the expected values and will

appear to be distorted.

Figure 6.10 - The DTFT and the DFT of signal [0, 2, 3, 0, 5]x

More on zero-padding

To improve this DFT plot, we add zeros to the end of the signal, so that it becomes

longer. We see in Fig 6.11(b), a denser sampling of the DTFT. We note that the DFT in

the first case had only 5 samples, where this one has 17 points. In both cases, the number

of samples in the frequency-domain are equal to the length of the signal. In the first case,

the frequency resolution was equal to 2 / 5 and in the second case it is 2 /17 radians, a

much smaller number. Recall the fence board analogy, in the second case the obscuring

fence boards are narrower, allowing us to see more of the DTFT. If we want to put this in

terms of frequency, we note that the sampling frequency in the first case is 5 Hz. Hence

the frequency resolution in that case is 5/5 Hz, or 1 Hz per bin and in the second case it is

5/17 Hz per bin. Or in other words each bin is located from one next to it by Fs/N Hz.

Page 23: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 23

Figure 6.11 - Adding a bunch of zeros to the signal improves the sampled

DFT resolution.

Example 6-3

Compute the DFT of this signal: .5 6x n n n for N = 8.

Although the actual signal length is 7 samples, let’s append a 0 to the end and make N =

8. The signal is [ ] [100000.50]x n .

For N = 8, 0 02 4N . This is a good resolution because both the impulses fall

exactly on one of the bins. Let’s compute the DFT of the signal as

0

0

21

0

278

0

278

0

[ ] [ ]

[ ]

[ ] .5 [ 6]

N jk nN

n

jk n

n

jk n

n

X k x n e

x n e

n n e

In the last step, the multiplication of the complex exponential by a delta function just

means that we grab the value of the exponential at the location of the delta function

which we do here for k = 0 and k = 6.

Page 24: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 24

2

8

2 2

8 8

0 6

3

2

[ ] .5 [ 6]

.5

1 .5

jk n

jk n jk n

n n

jk

n n e

e e

e

Now we finish the job, noting that index n is gone.

372

0

3

2

[ ] 1 .5

1 .5

jk

n

jk

X k e

e

Computing the 8 values of the DFT, we get

Page 25: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 25

Figure 6.12 - DFT of a signal with different amounts of zero padding, size = 7, size = 8, size = 128

The result is plotted in Fig. 6.12 and appears to be sinusoidal, just as we should expect

from two impulses. Note that the values have conjugate symmetry. This is always true of

DFT and allows us to reduce the number of calculations. We did the analysis for 8 points.

Now we do exactly the same thing for 28 and then for 64 points by padding the end of the

signal with a lot of zeros as we see in the left column of Fig. 6.12.

As N gets larger, we get a better defined DFT. Zero padding gives more points of

interpolation into the DTFT. However, caution is warranted if the signal contained a

higher frequency signal beyond twice the sampling frequency, zero-padding would do

nothing to help discover it. So although we say that zero-padding improves resolution,

but the strict meaning of that word implies the ability to resolve two closely spaced

components in the spectrum. That we do not get with zero-padding, and the only way to

get better resolvability is to obtain more data. The correct interpretation for what zero-

padding does is to provide improved interpolation density, just like using more points to

plot a curve given its equation. It does not change the equation, only the number of

points plotted.

Example 6.6

A signal is sampled at the rate of 100 Hz and is band-limited to 25 Hz. The number of

samples is 50.

(a) What is the bin spacing?

Page 26: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 26

(b) What frequency is represented by k = 20 and k = 40?

The DFT size or N is equal to 50. Each bin represents a frequency resolution of 2 Hz

(100/50) which is the spectral spacing since

ss

FR

N

Bin 20 represents 40 Hz and bin 40 represents 80 Hz.

What if this signal was sampled at the rate of 25 Hz instead of 100? What would be the

value of these bins then? Sampling frequency of 25 Hz is less than the minimum rate

(needs to be 50 Hz because the signal has a bandwidth of 25 Hz) and we get aliasing. The

spectral resolution is 0.5 Hz. For bin 20, we get 10 Hz, and 20 Hz for bin 40. This is

beyond the 12.5 Hz range of the DFT, so at bin 20 we will get aliases from the adjacent

spectrum value and the answer would not be correct.

Smearing from sampling incomplete cycles

Let’s examine the DFT of a sinusoid of frequency 2 Hz sampled with sampling frequency

of 16 Hz, for two different lengths, N = 16 and N = 12 samples using Matlab.

The number of samples collected is 16 samples per second. Hence we get 8 samples per

period. 16 samples means we have samples from two full periods. However, when only

12 samples are collected we get just one and a half periods.

From this information, we can write out the expression for 8[ ] cos(4 )nx n . Using

Matlab we collect 16 samples, and develop the DFT which is plotted in Fig. 6.13.

Remember that DFT always thinks that N points used in the analysis is the period of the

signal!

Page 27: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 27

Figure 6.13 - The DFT of a sinusoid as a function samples collected (a) Signal length = 16, DFT length = 16, DFT in (b) is perfect. (c) signal

length 12, DFT length = 12, (d) DFT is bad.(e) signal length = 12, DFT size = 16, (f) DFT is a little better

In Fig. 6.13(a) the analog signal and its 16 samples are shown. In (b), we see a 16 Point

DFT. The DFT looks perfectly reasonable. We expect two impulses at 2f Hz and that

is exactly what we get from Matlab. In (c) we collect only 12 samples, and then we do a

12 point DFT on these points. Well what happened here? The DFT in (b) was perfect

since this is a pure sinusoid but in (d) we see a very noisy version of the DFT in (b), if it

is even that. The change in number of samples changed the DFT. We have two variables

here, N the number of time domain samples and then the size of the DFT, which maybe

longer than N if the signal is zero-padded. These numbers are independent. We can pick

the size of the DFT to be bigger or smaller than the number of samples available; that is

up to our good judgment.

There can be two reasons for the noisy result, we think. One is that in the second case, we

did a DFT of only 12 points, and 12 points do not cover a full integer number of periods.

So to try to correct our error we do a 16 point DFT on these 12 samples, but the DFT in

(f) is still not perfect, as compared to (b). So increasing DFT size to 16 , we essentially

zero-padded the 12 point signal by 4 zeros, and then did a 16 point DFT. It helped some

but not enough. Something is amiss. Fig. (b), (d) and (f) are different even though the

signal is the same.

The second guess is that the samples collected do not represent the actual periodic signal.

What the DFT actually “thinks” is that it has the signal in (b) in Fig 6.14 and not the

Page 28: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 28

continuous cosine that you are thinking, as in (a). The DFT algorithm is based on strict

periodicity, hence the signal we have used for analysis (12 samples do not result in a

periodic signal!) violates this assumption. It has a large discontinuity at the end points.

These discontinuities result in frequency components to appear in the DFT that aren’t

there and are a consequence of the fact that we truncated the signal in the “wrong” place.

Figure 6.14 - (a) What you think signal looks like and (b) what the DFT is

thinking.

Truncation effect on the DFT

When we collect a signal, any signal, we are “truncating” it. If we are lucky, we do it

in such a way that we obtain samples from exactly an integer number of periods,

hence meeting the periodicity requirement. But that is unlikely with random signals.

Just because we can “do” a DFT on any and all collected samples does not mean that

what we have get is mathematically valid. The DFT will give accurate and expected

answers only if the signal meets certain conditions. In Fig. 6.13(a), where 16 points

were collected and which cover exactly two periods of 8 samples each, the DFT is

representative of reality. But if we don’t truncate correctly, what then? We see that

the result is unexpected and leads us astray, with DFT giving answers based on its

own alternate reality. Let’s try to understand this effect.

No matter how many samples we choose, by choosing a certain number we are in

essence multiplying the signal with a truncation function. This is what we call a

window. Although in reality we just stop taking data or we just turn off the machine.

In mathematical sense, we were multiplying the infinite signal we were measuring

with a truncation function consisting of a window of all 1’s while we were measuring

and then zeros thereafter. Sort of like an on and off switch. This seems like a benign

and even ridiculous thing to talk about. Of course, we have to stop collecting the data

somewhere! And yet, any time we stop, we truncate the signal, we have multiplied it

Page 29: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 29

with an N point all 1’s rectangular function. This is a rectangular function and we

have seen that it has a non-trivial transform, a transform the in the shape of a sinc

function. This window and its Fourier transform now becomes part of the truncated

signal. This is the effect of working with finite data and inherent truncation effects.

The target analog signal frequency in Ex. 6.8 is 2 Hz frequency. It is being sampled at

16 samples per second, hence in one second we collect 16 samples, which covers

exactly two periods. If you do a DFT on these 16 points, you get a DFT in (b), with

two impulses. Let’s take a moment now to discuss the x-axis of the DFT again. There

are k = 16 harmonics in this case. Each bin advances the frequency by 1 Hz. The

underlying signal is 2 Hz, bins at k = 2 and k = -2 are situated at exactly the right

place to measure the quantity of this frequency. The impulses represent half the

amplitude of the signal. There are no other frequencies in this signal that contain any

energy to measure.

Now we look at exactly how we gathered the 16 points, In (b), we see a square pulse

of 16 samples. The sampled signal is actually a particular signal times this 16 sample

Rectangular truncation function. The DTFT of this truncation function is a Sinc

function that we see in the dashed line. However doing a 16 point DFT of the Sinc

function gives us zeros at the sampling instants when the sampling instants are integer

multiple of , except at 0. But you see what is really happening behind the scene. We

happen to be sampling at integer multiple of , the points where the response of the

sinc is zero. Had we not sampled exactly at these integer multiples, we would get

different values for the DFT.

The DTFT of the truncating rectangular function however is not always a benign

function but is capable of giving us unexpected values in the frequency domain. It

happens when our bins do not fall on the exact frequencies of the underlying signal.

Page 30: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 30

Figure 6.15 – Perfect truncation occurs when the bins coincide with the

exact frequency of the signal.

Now instead of collecting 16 points, we collect only 12 points. This gives a frequency

resolution of 16/12 = 1.333 Hz. Each harmonic index k and k+1 differs in frequency by

1.33 Hz. In Fig. 6.16 (d) we see the DTFT of a 12 point window function. In (f), when we

do the DFT of the 12 point sample, it gives us a summation of two displaced sinc

functions which at their peak values do not align with the bins. The bins are located at a

spacing of 1.33 Hz and the signal frequency is at 1 Hz. So the energy in the 1 Hz

components is spread among adjacent bins. The process of spreading, also called

smearing is a function of the truncation window type and length.

Page 31: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 31

Figure 6.16 - When the frequency of the signal does not coincide with a

bin, the energy is spread across several bins.

Of course given a bunch of random samples, we never know if we have an integer

number of periods, and whether or not every single frequency component will align

perfectly with our chosen sample size. Hence smearing is nearly always present in the

DFT/FFT of real signals. We are always going to get this sort of distortion. We can either

tolerate this error (acceptable if small) or do something to eliminate or reduce it.

We can explain the smearing shown in Fig. 6.16(d) by noting that the signal has been

windowed using a 12-point square wave. Multiplying two signals in time-domain is same

as a convolution in frequency domain, so we can write the relationship of the finite-time

spectrum as a convolution. The DFT of a truncated or windowed signal is the result of the

convolution of the DFT of the infinite repeating signal with the convolution of the DFT of

the finite-time window.

( ) ( )* ( )

[ ] [ ]* [ ]

w

w

x t w t x t

X k W k X k

Our signal is a sinusoid and we know that its transform looks like two impulses, centered

at the sinusoid frequency around zero.

0 0[ ] [ ] [ ]X

The DTFT of the window function, which is a square pulse function is a Diric (repeating

sinc) function. Its DTFT is given by

1

22

2

sin( )

sin

Nj N

W e

This function plotted in Matlab using

N = 16;

om = 0: .01: 2*pi;

x = exp(-1i*om*(N-1)/2).*diric(om, N)

plot(om-pi, fftshift(20*log10(abs(x))))

axis([-pi pi -40 0])

grid on

Page 32: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 32

We see it in Figure 6.17. It is plotted in dBs. It shows the effect of the rectangular

function on the DTFT of the signal. We see that it distributes or smears each component

that does not fall on an exact bin, according to this pattern.

Figure 6.17 - The power spectrum of a rectangular truncation signal

Now we compute the DTFT of the truncated signal by convolution of the two transforms.

1

220 0

2

( ) ( )* ( )

sin* [ ] [ ]

sin

m

Nj

X W X

Ne

If you look carefully, you can figure out what this convolution does. Operations with

delta functions are fairly easy. The first delta function copies the sinc function in Fig 6.18

at and the second delta function creates another copy at . These are superimposed

and create a smeared double peak spectrum as shown on RHS.

Figure 6.18 – The DTFT and DFT of the windowed cosine.

The DTFT of the window function is shown in the dashed line. It is a continuous

function. The DFT however, is sampled values of this function, the 12 values in keeping

with the original 12 sample data. If we did not plot the DTFT, all you would see are the

Page 33: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 33

two impulses and a bunch of zeros, exactly what you would expect as the DFT of a

cosine signal. That’s because the frequency resolution is 1 Hz and aligns exactly with the

sinc function zero-crossings.

The Figure 6.19(d) shows this in detail. We have plotted the response for the first case

with N = 12. The peak of the DTFT falls exactly at 1 Hz which is also a bin and hence

we see a DFT sample at this point. The peak for case with N = 18 samples occurs instead

at bin 1.5 and hence there is no bin there, the DFT values comes from the two bins that

straddle it. The DFT values are different because the underlying DTFT has changed

when we changed the sample count.

Figure 6.19 - examining the two cases for N = 12 samples and N = 18

samples. When N is 12, DTFT and DFT align on bins, but not when N = 18.

Page 34: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 34

Figure 6.20 - Another example of the bins not aligning with frequencies. (a) Signal sampled with Fs = 16, (c) Same sampling frequency but underlying signal has

changed such f1 = 2.3 Hz and f2 = 4.66 Hz., (e) same as (c) but a longer DFT has been computed. This reduces the effect of the smearing.

In Fig. 6.20(a) we look at a signal which is a sum of two sinusoids. In the first case, we

set the frequencies of the two sinusoids to 2 and 4 Hz. The sampling frequency is 16

samples per second. Note that if we do a 16 point DFT, then the frequency resolution is

16/16 or 1 Hz. Hence the signal frequencies, both 2 and 4 Hz fall on a bin. Hence the

DFT shows the exact frequency with only four impulses, one for each frequency. This is

a text book scenario. Real signal don’t have such integer frequencies. So for the next

case, we change the two frequencies in the signal to 2.3 and 4.667 Hz. This time, we

decide to do a 128 point DFT. Note that we only use 16 collected points, one second

worth of data but then we zero pad it to be 128 points long. The DFT of this signal does

not look like the first case. The signal energy at both frequencies is spread across some

number of bins. If we increase the DFT size to 1024 points, the frequency resolution

becomes quite small, 16/1024 Hz. The spectrum is now looking quite good. The low

frequency signal amplitude are nearly equal to (b). The higher signal energy is spread in

two bins.

Conclusion is that a longer DFT is usually better than a shorter, zero-padding does not

always improve the resolution and truncation effects are always there.

Page 35: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 35

Reducing truncation effects

How can we reduce this leakage/smearing due to truncation? What if we do not know

ahead of time the period of the signal and no way of knowing if we have collected the

samples from an integer number of cycles? The significant point about periodic signals is

that they match at the end points. We can fake the periodicity by forcing the end points to

be zero. If we do that, the piece will have no discontinuities, the right side matches the

left since they are both zeros.

We can do that by multiplying the time domain signal with a shape that forces the end

points to zero. This is artificially distorting the signal, literally bending the signal down to

zero, so as far as the DFT is concerned the signal now appears periodic. Zero ends mean

that this is one period and the next period, also with zero ends will slide right up against

it hence completing the illusion of periodicity in the “mind” of the DFT. Rectangular

window cuts the signal where it is, it is not distorting any points, so it does not work for

this purpose. This would require a non-rectangular window, one that tapers to zero. No

matter what the amplitude of the last few points, such tapering windows push the points

down to zero. Windowing changes/distorts the signal and in that it is quite different from

zero-padding. Rectangular windows or just straight forward stopping data collection

suddenly are actually the worst at leaving deep discontinuities in the signal.

Figure 6.21 –(a) sinusoid samples and a “window”, (c) the windowed

samples, (b) DFT of the un-windowed samples, (d) the DFT of the windowed samples. The DFT in (d) has the least amount of noise, although

the lobes are wider.

In Fig. 6.21 (a), we have created an arbitrary window function, shown in the solid line

in order to force the end points to near-zero. In (c), we see the samples multiplied by

this window function. The end points are now near zero. Its DFT in (d) shows some

improvements over the one for the actual samples in (b). Comparing the DFTs, in (b)

and (d), the noise is less in (d) but not much else. The main lobe is a bit wider as well.

Can we do better? We make this observation: perhaps there are other window

functions that work better, better at reducing the noise as well as enhancing the main

Page 36: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 36

signal components. We will discuss this topic, called Windowing in Chapter 7 as it is

important in dealing with smearing introduced into the spectrum from injudicious

(but all too common) truncation.

DFT of the ever important Sinc function

When the input is a sinc function, such as

Then its DTFT is given as

This is a rectangular function or an ideal filter of bandwidth, W Hz. In theory, the sinc

signal would give a perfectly flat top-hat like spectrum as shown in (b) because a

sampled sinc function is a one single impulse, since it is sampled at only the zero-

crossings. But because we are unable to create an indefinite length Sinc pulse, we don’t

get a perfect-flat top, as we see Fig. 6.21 the shape of the response as a function of the

length of Sinc pulse.

Figure 6.22 – A sinc pulse of infinite length has a top-hat like DTFT.

Page 37: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 37

For case (a), the first zero crossing occurs at n = -1 and +1. The value of the function is 0,

which means the argument of the function is equal to , which is true since 1sF .

n 1, 1

sin ( ) 0

s

s

F

c n F

In frequency domain, the function is zero at 64k . The x-axis in the frequency

domain can be described as spanning 2sF

to 2sF

or from -.5 to +.5. The frequency

resolution hence of each harmonic index k is equal to Fs/N = 1/128 hz. Hence k = 64,

equals 0.5 Hz.

For case (b), Fs = 2, and we now have twice as many points as in case (a). This is a true

sampled and truncated version of the first ideal case. We are basically truncating the sinc

function to 10 points on each side. In the frequency domain, the frequency resolution is

equal to sF N or 2/128 Hz. The signal bandwidth spans from 32k . At -32, This is

converted to frequency by multiplying it by frequency resolution of 1/64 Hz, getting

again .5 Hz, same as the first case. In case (f), sampling frequency is equal to 4 samples

per second. He have four times as many samples. The frequency resolution sF N is equal

to 4/128 Hz. At k = 16, we a frequency of 16*4/128 or 0.5 Hz.

DFT repeats with sampling frequency

But let’s not forget that the DFT repeats with Fs. Notice that each “square” pulse is

centered at integer multiple of the sampling frequency.

Page 38: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 38

Figure 6.23 – When sampled with Fs = 1.5, 2, and 3 Hz, the DFT repeats with same frequency.

Up-sampling and seeing images

Now we take the 20 samples a signal, any signal, and zero pad these to 128 samples. A

question? Do we add the zeros at the end of the samples as we said before, like this or do

we do this as in Fig. 6.22 (b), half on each side? Which is correct and what is Matlab

doing?

Figure 6.24 – Where to add the zeros to the samples? At the end or on

each-side? Does it make a difference?

Previously we said that zero padding means appending zeros at the end of the signal. But

how about if we zero-pad at each side? Would that make a difference in the DFT. Well,

yes and no. This is basically a time shift, phase will change but the magnitude stays

exactly the same as we said before. So if we are not interested in phase and yes, phase

can be sometimes be ignored, we can add the zeros on either side of both.

Now we ask, what happens, if instead of adding zeros at the end of the time domain

signal, we stick them in between the samples.

Imagine two impulses around 0. This corresponds to a cosine in frequency domain. Now

imagine inserting extra zeros at each end, what happens? Nothing. The signal retains its

frequency domain behavior. Now add zeros between the origin and the samples, the

result is a new signal. The two impulses when moved further apart represent a different

frequency. Hence when we are inserting zeros between the samples, we are basically

changing the frequency response of the signal. This case of inserting zeros in between the

samples is not benign as is adding zeros at the ends.

In Fig. 6.24 (a) we see an arbitrary signal with its DTFT in (b). Now we expand the

signal by inserting three zeros in between each sample and then do its DFT again. The

effect is surprising. The interpolation by a factor of 4, results in the spectrum duplicating

Page 39: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 39

4 times. What is happening here? Is this same as replication with sampling frequency?

The answer is no, it is not. These four copies are called the images of the spectrum.

Figure 6.25 – Effect of interpolation

In Chapter 4, Table I, we give a property of the CTFT called scaling. The property says

that if a time domain signal is scaled by a factor a, then its Fourier transform scales by

the inverse of the scale factor.

( ) X( )

1x(at)

x t

Xa a

(6.17)

Hence if a signal such as the one in Fig. 6.24 (a) is sped up by a factor of 4, then its

frequency resolution decreases by 4. When we insert zeros in between the samples, we

are actually changing the essential nature of the signal and its frequency distribution. We

are changing the sampling rate of the signal. This brings us into the realm of multi-rate

signal processing. Mutli-rate signal processing is often necessary when different parts of

a system have different bandwidths and require different sampling frequencies in order to

keep their sampling rate at the Nyquist rate. To make multi-rate sampling work, filtering

the images is always necessary and hence the term upsampling becomes interpolation

when combined with filtering. Similarly when a signal is down sampled, it too has to be

followed by filtering, a process called decimation.

Page 40: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 40

Fig. 6.26 - Example of a band limited up-sampled spectrum

In Fig. 6.27, we see a signal that has been up-sampled by a factor of 5. We note that its

spectrum in (d) is indeed images and not the replicated spectrum. The images are

reversed in pairs because the DFT of the un-upsampled signal is not symmetrical.

Lets’ see if we can examine the mathematical basis for this repetition. Assume that we

are going to insert M-1 zeros between each sample of an N-sample signal. The new

signal generated from the old signal is given by

[ ] 1, 2

[ ]0

x n for My Mn

else (6.18)

In this case if M = 4, then y[4] = x[1] , y[8] = x[2], y[12] = x[3] and in between values

are all zeros. We calculate the DFT of this stretched, up-sampled or interpolated signal by

1

0

1

0

[ ] [ ]W

[ ]W

MNnk

s MNn

NnkMN

n

Y k y Mn

x n

(6.19)

The index MN is changed to n, as it is not a factor of M, and we change k to 0, 1, … to NM-1, we rewrite this as

1

0

[ ] [ ]W [ ]N

mks N

n

Y k x m Y k (6.20)

This says that we get a spectrum at every N samples instead of NM samples. The

spectrum of the up-sampled sequence is same as that of non up-sampled sequence but is

Page 41: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 41

spread over M periods. The stretching via the addition of the zeros in between the

samples, does a shrinkage of the resolution of the spectrum. However it is still an exact

sampling of the DTFT and can be filtered and the original signal can be recreated from a

single image.

Down-sampling

When a signal is down-sampled, we are doing the inverse. The signal is being sampled at

slower speed by a factor of M, as we can see in Fig. 6.27. The DFT of the signal is

limited to pi/5 in (b) but when the same signal is down-sampled by a factor of 3, its DFT

spreads by a factor of 3 as in (d). At this rate of down-sampling, the time-domain signal

still retains some similarity to the original signal and hence its spectrum is also near

identical shape of the original. However when the same signal is down sampled by a

factor of 6, it both loses its similarity in time domain to the original and its frequency

response. This is somewhat intuitive. You cannot keep removing information and still

expect to be retain the essential nature of the signal.

Figure 6.27 – Downsampling of the signal by a factor of 3 spreads the spectrum by a

factor of 3. Larger down-sampling as in ( e ) may distort the spectrum depending on the

spectrum bandwidth.

Interpolation

The up-sampled signal where zeros are added is a signal that has not been interpolated.

At these points, we essentially have no information. But what if we do some sort of

Page 42: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 42

interpolation on these intermediate samples. The process of interpolation consists of

guessing these intermediate values based on available data. The simplest thing we can do

is sample-and-hold operation on the signal. Or perhaps a different interpolation method.

How would that effect the DFT? In Fig. 6.28, we see three different types of

interpolations of signal in (a), (b) with zero-insertion which is basically up-sampled, (c)

with zero-order hold, in (d) first order hold or linear interpolation. We take the signal in

(a) and in (b), we insert zeros, in (c), we hold the value for 3 samples, and in (d), we

linearly connect the original points in over 4 samples. In Fig. 6.28, we see the DFT of

each version. Only the DFT of zero-insertion, gives us significant images. The reason is

that the other methods by having interpolation performed on them have in-effect filled in

the zeros, whereas no such interpolation has occurred for the zero-insertion case and

hence all the images are present for to us to see. Interpolation adds information and in the

process removes the images.

Figure 6.28 – The DFT of the signal with various types of interpolation

DFT of the zero-added signal shows M images, (b) DFT of the zero-order hold signal still has some level of images (c) DFT of the first-order hold signal and (d) the DFT of the spline interpolation are nearly perfect with no images.

Doing convolution using DFT

Page 43: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 43

The convolution property is one of the most utilized properties of Fourier transform. This

property states that the multiplication of two functions in one domain is convolution in

the other domain. However for discrete signals of finite length we get a complication in

the application of this property. The convolution required to make the relationship work

for finite length signals is of the form called circular convolution instead of the linear

convolution that we know, and don’t love. Circular convolution is not much easier to

comprehend either. Let’s look at the math first. Say we have two time domain sequences

of finite length, [ ]x n and [ ].h n Their DFT over N samples is given by [ ]X k and [ ].H k

We now examine this relationship to see if the convolution property is true. We multiply

the two DFTs and then take the iDFT of the product. The result should be a signal which

is the convolution of [ ]x n and [ ].h n

2

1

0

1[ ] [ ] [ ]

kN

Nj n

k

y n H k X k eN

(6.21)

We want to see what we get when do this math. Is this [ ]y n the same as the linear

convolution of [ ]x n and [ ]?h n Expression (6.21) is equal to

2 2

2 2

1 1

0 0

1 1

0 0

1[ ] [ ]

1[ ] [ ]

k mN N

k kN N

N Nj m j n

k n

N Nj m j n

m k

h m e X k eN

h m X k e eN

(6.22)

The underlined part is the iDFT, hence it is a replicated form of [ ]x n which we will

denote as [ ]Nx n . The signal is presumed by the DFT to repeat with period N. The

multiplication by 2 m

Nj n

e implies a shift in time domain of units m. So we rewrite this

equation as

1

0

[ ] [ ]N

Nm

h m x n (6.23)

So yes, we get a time domain multiplication but the replicated signal [ ]Nx n is not the

same thing as [ ]x n , as we see in Fig. 6.29.

To see an example, we select two arbitrary signals, [ ]x n and [ ],h n [ ] [1,2,3,4]x n

[ ] [1, 1, 1,1]h n .

Let’s do their linear convolution, which means to hold one signal fixed, reversing the

other and then doing a point by multiplication of all overlaps and adding these to get a

Page 44: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 44

value at that shift. We use Matlab to do the linear convolution using the command, conv,

to get the following sequence.

[1 1 0 0 -5 -1 4]y

Figure 6.29 – Linear vs. circular convolution, (a) and (b) are two

sequences, (c) linear convolution and (d) DFT result which is circular convolution.

Now we will use the DFT to compute the convolution. Since the signal length is 4 points,

we will just do a 4 point DFT. We get the following two DFT’s.

[ ]=[ 10.0000 2.8284 2.0000 2.8284]

[ ]=[ 0 2.8284 0 2.8284]

X k

H k

We multiply these and do an inverse DFT to see if we get the same y sequence. No need

to do the DFT, as we know that we will not get a 7 point sequence from the

multiplication of two 4 point DFTs. However let’s take a look at what we get.

[0,4,0,4]y

In Matlab, we invoked cconv(x, y, 4) command to get this result. This just so happens is

the circular convolution of the two sequences, x and h, and not linear convolution.

Hence the DFT convolution property works only with circular convolution and not linear

convolution. The process of circular convolution is different from linear convolution. So

what if we wanted linear convolution and not circular? We can get the linear convolution,

if we pad each signal to be equal in length to ( ) ( ) 1length x length h or greater.

Let’s look at the linear and circular convolution of these two padded sequences.

Page 45: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 45

[1,2,3,4,0,0,0]

[1, 1, 1,1,0,0,0]

x

h

Now when we perform this calculation, we do get the linear convolution.

( ( ) ( ))N paddedN paddedNy IDFT DFT x DFT h

Y = 1.0000 1.0000 0.0000 0.0000 -5.0000 -1.0000 4.0000 0.0000

Which is indeed the linear convolution.

Figure 6.30 - Linear vs. circular convolution via DFT (a) and (b) are convolved. If the length of the DFT is equal to 2N-1, then we get linear

convolution, otherwise we get circular convolution.

Why do we even bother with the DFT to compute the convolution if can do it directly

anyway? The reason is we find that DFT is in fact a computationally efficient method of

computing linear convolution. Machines don’t like to compute convolution either, its that

boring! The actual reason is that if a hardware device already has a built-in facility to

compute a FFT, then why design a new algorithm to compute the convolution, why not

use the DFT for convolution too. But if not done right, the answer DFT gives is the

circular convolution. Algorithms have been developed to take this into account and to

automatically extend and zero-pad the signals to produce the correct answer. Using the

DFT to compute the convolution is often called Fast convolution, since it requires less

computational effort than the direct method.

There are some methods that make the calculations even more efficient. The two most

popular methods are called Overlap-and-Add and the Overlap-and-Save method. In both

of these method the input signal is subdivided in smaller blocks which are convolved

with the impulse response of the filtering sequence h[n]. This subdivision reduces the

number of multiplications and makes both of these algorithms very efficient.

Page 46: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 46

Short-Time Fourier transform

To have a valid Fourier transform a signal must be time invariant, which means its

amplitude, phase and frequency content cannot be a function of time. So what about a

signal like this one? This is a signal where the frequency is changing continuously.

2[ ] sin 2 ox n A f n

This type of signal is called a chirp signal. Here we plot one with f0 = 100 Hz and A = .5.

In Matlab, we frame such signals with three parameters shown in (a). Here the starting

frequency of 100 Hz is expected to become 300 Hz in one second time.

We could run this through a DFT but we know this is wrong. Can we even use the DFT

on such a signal? Like the engineer who invented the STFT, we go ahead and give it try

recognizing that if we make the DFT size small, then we can assume that the frequency is

not changing over this short interval. Maybe we can still use the FFT to extract useful

information from this signal and from many like it. The way to do that is to subdivide the

signal into some very short time intervals, which allows us think of the signal as

stationary and time-invariant over a small time period. We can do a DFT on each small

segment and then look at the changes in the DFTs of these segments in time. People have

learned to read and use this time-varying DFT, called the Short-time Fourier

Transform. STFT actually has three dimensions, time as well as frequency and the

magnitude. Plotting all three will make it a 3-D plot. A 2-D version of the STFT is called

spectrograph as implemented in Matlab. Here in Fig. 6.31, we show the STFT of the

chirp signal computed in Matlab by using two different set of parameters. We note in

each of the two STFTs, the y-axis is time and x-axis is frequency. We see that the signal

frequency starts at 100 Hz and is about 300 Hz one second later, just what the input

signal is. We see in both (b) and (c) that the frequency varies linearly with time, and that

is true since we chose a linear chirp. The fuzzy-ness of the line indicates the range of

frequencies over each time range. STFT is often used for audio signals, where variety of

qualitative assessments can be made on a signal using the STFT.

Page 47: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 47

Figure 6.31 – Short-time Fourier transform (a) a chirp signal with f0 = 100 Hz, (b)

Spectrogram with segment length = 128 and no overlap, (c) Spectrogram with

segment length = 256, overlap = 64.

DFT in real-life

When we have a large amount of data and we select a subset of it to do a DFT, how do

we know which part to choose, where to start?

Figure 6.32 - A large amount of collected data. Where to do the DFT?

Page 48: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 48

6.32(a) shows both I and Q channels of a signal. The signal has gone through a non-linear

amplifier which distorts the input signal in both amplitude and phase. We note that the

signal has some transient behavior at the beginning. This would not be a good place start

the DFT since Fourier transform requires a signal that is not changing in average power.

Hence we should skip this part. We should pick something in the middle or at the end,

and select a number of samples that we have already determined we need.

Fig. 6.33 shows 4096 point DFT of the signal, one done at the start which has a transient

nature and the second done on the steady-state part of the signal. This is a digital signal,

shaped with a root raised cosine filter of roll-off 0.2. The signal contains no noise and yet

look how noisy it is, unlike any of the ones we have been seeing. The reason for this is

that this is a random signal. We were not particularly careful where we started the DFT.

Ideally we should start at the beginning of a symbol. We should also sample at a rate that

is an integer multiple of the symbol rate. But this is often an impractical condition to

meet. We work with what we have.

We see that the two DFTs are different often by several dBs. Although because this is a

random signal, the DFT has a lot of variance, which of course means, it is hard to read

and varies far too much from one bin to the next.

Figure 6.33 - The (DFT) of a random digital signal done at two different

points in the signal. The DFT is different because the signal for case (a) is in a transient or changing zone.

This variability of the DFT is quite bothersome but cannot be avoided. We are interested

in judging the average level of the signal, and we find it varying as much as 5-10 dB

from bin to bin. For this reason direct DFT is not often used to compute the power

spectrum of random signals. In Fig. 6.34 we plot a smoothed version of the DFT called

the Periodogram. This clearly looks much better than Fig. 6.33 but these looks are

obtained at a cost. This smoothing sacrifices resolution for reduced variance and ease of

qualitative understanding. This is a topic we discuss in chapter 8.

Page 49: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 49

Figure 6.34 - The output power spectrum

Fast Fourier Transform (FFT)

The acronym, FFT is so ubiquitous that we even use it synonymously for DFT. So

common is this usage that one does it without thinking. FFT is now the Kleenex of the

DSP world.

The DFT although clear and easy to compute, requires a good many calculations. For

each harmonic, we have N multiplications and we do this N times, giving us

approximately N2 calculations, referred to as multiply-and-accumulate (MAC) operations

in DSP. A 256 point DFT would require 65792 calculations. The algorithm for Fourier

transform existed for more than 200 years before it came into widespread use mostly

because we could not cope before the advent of the digital computers with such large

number of computations. The algorithm waited for the development of the

microprocessor.

In 1965, Cooley and Tukey came up with a computational breakthrough called the Fast

Fourier transform algorithm. This was an ingenious manipulation of the inherent

symmetry in the calculations. It allowed the computation of an N point DFT as a function

only 2logN N instead of the N2. So a 256 point DFT would only require 2048 MAC

calculations, a huge improvement from 65792 calculations doing it the long laborious

way. The algorithm was quickly and widely adopted and is the basis of all modern signal

processing.

Most DSP books spend a lot of time going through the mechanism of the FFT and how it

is computed and implemented. All those butterfly figures in books help to confuse and

confound us as to what is actually going on. Most of us just give up on it. Let me

alleviate your guilt. Although extremely important in itself, the understanding of the

mechanism of how the FFT is “calculated” is not all that important. So, we are not going

to cover FFT calculation algorithm in this book. This statement maybe an anathema to

some reading this book. We justify that omission by noting that this is a book about

Page 50: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 50

understanding the Fourier transform and how to apply it. Its efficient computation, we

leave to others.

The FFT algorithm has been programmed in all sort of software and we can safely skip it

without impacting our understanding of the application of the DFT and the FFT. In

Matlab, you can do a FFT of any size. Of course in hardware, efficiency is important so

the FFT algorithm (and there are several versions) is based on signal size N, such that N

is a number generated by an integer power of 2 or is equal to 2kN , with k an integer.

This is not a big issue. The only time we find ourselves wanting to do DFT/FFT of a

number other than on a number that is power of 2 is in textbooks and for illustrative

purposes. Even in Matlab if you use a signal that is not a power of 2, it uses a slower

version of the FFT. We assume that the FFT implementation is a black-box, into which

we feed the data. As long you understand what this box is doing, understanding how

efficiently it is doing its job is not that important.

The main thing one needs to know about the hardware-based FFT is that it works with

sample sizes that are powers of 2, such as 16, 32, 64 etc. We cannot do a FFT on an

arbitrary number of samples as we can with DFT or FFT in Matlab, which is used mostly

for educational purposes process. The FFT is a DFT with constraints on the number of

input samples.

The other thing about the FFT process to know is that it allows zero-padding. Let’s say

we have 28 samples and we wish to do a DFT via the FFT, we can do two things, 1. we

can do a 16 point FFT and discard the remaining 12 points or we can insert four zeros at

the end so we have 32 points. Now we can do a 32 point FFT. The zero-padding provides

us better resolution but does not provide any extra information. The frequency detected is

still a function of the original N samples and not the zero-padded length, although the

FFT does look a lot better. And looks do count.

Page 51: Discrete Fourier Transform - Complex To Realcomplextoreal.com/wp-content/uploads/2015/07/Chapter-6.pdf · Discrete Fourier Transform (DFT) borrows elements from both the discrete

Chapter 6 - Discrete Fourier Transform (DFT)

ComplexToReal.com Page 51

Summary of Chapter 6

1. The DTFT spectrum is continuous with frequency and requires an infinite length

signal, hence it is not practical.

2. The DFT is a sampled version of the DTFT computed at selected frequencies.

Those selected frequencies are given by

20,1, 1k

kk N

N Where N is the number of samples.

3. The DFT as samples of DTFT is given by

02

[ ] ( ) ( )k

X k X X k XN

4. DFT is formulated from the DTFT for a finite number of points as given by

21

0

[k] [ ]k

N

Nj n

n

X x n e

5. The DFT takes N uniformly placed time domain signals x[n] and creates a

spectrum which we call the DFT.

6. The x-axis of the DFT can be given three ways; by k the bin number, by phase

over , range or by the frequency, ksN F . The spectrum is discrete and

repeats with sampling frequency.

7. The spectrum is said to cover 2 radians or in frequency from / 2sF to +Fs/2

where Fs is the sampling frequency of signal.

8. Zero-padding can be used to improve the interpolation density. It is like using

more points to plot a curve given its equation. It does not change the equation,

only the number of points plotted.

9. Truncation effects can be significant in a DFT if exact signal amplitude and

locations are desired from the spectrum. These can be mitigated by using longer

N, or an integer number of periods.

10. DFT can be used to implement fast convolution.

11. Fast Fourier Transform is an algorithm that uses signal lengths of 2N. It speeds up

the computation using symmetry properties of the DFT.

Copyright Charan Langton, 2015 All Rights reserved.