the fast fourier transform · an illustration of part of the fft algorithm fft v dft two examples...

27
20/07/2020, 19: 59 fft Page 1 of 27 http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false The Fast Fourier Transform Colophon An annotatable worksheet for this presentation is available as Worksheet 19 (worksheet19) . The source code for this page is dft/1/dft.ipynb (https://github.com/cpjobling/eg-247- textbook/blob/master/content/dft/2/t.ipynb) . You can view the notes for this presentation as a webpage (HTML (https://cpjobling.github.io/eg- 247-textbook/dft/2/t.html) ). This page is downloadable as a PDF (https://cpjobling.github.io/eg-247-textbook/dft/2/t.pdf) file. Scope and Background Reading This session introduces the fast fourier transform (FFT) which is one of the most widely used numerical algorithms in the world. It exploits some features of the symmetry of the computation of the DFT to reduce the complexity from something that takes order ( ) complex operations to something that takes order ( ) operations. 2 ( ) 2 log ( log ) The FFT is to be found in all manner of signal and image processing algorithms, and because it is more ecient than the DFT, you will find it exploited in hundreds of signal processing applications. As one example, it turns out that the computation of the convolution of two long DT sequences is more ecient if the FFT of the two signals is taken, the product of the frequency spectra is computed, and the Inverse DFT of the result is computed. In this presentation, we will not go through the mathematical development of the FFT, please read section 10.6 of Karris if you want the details. Here we will concentrate on the benefits to be gained by using the FFT and give some examples of its use in MATLAB. Acknowledgements The material in this presentation and notes is based on Chapter 10 (https://ebookcentral.proquest.com/lib/swansea-ebooks/reader.action?docID=3384197&ppg=405) of {cite} karris from the Required Reading List. The models of the FFT signal flow graphs and Simulink block diagrams are based on the presentation given in Section 12.5 of {cite} phillips .

Upload: others

Post on 24-Aug-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 1 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

The Fast Fourier Transform

ColophonAn annotatable worksheet for this presentation is available as Worksheet 19 (worksheet19).

The source code for this page is dft/1/dft.ipynb (https://github.com/cpjobling/eg-247-textbook/blob/master/content/dft/2/fft.ipynb).You can view the notes for this presentation as a webpage (HTML (https://cpjobling.github.io/eg-247-textbook/dft/2/fft.html)).This page is downloadable as a PDF (https://cpjobling.github.io/eg-247-textbook/dft/2/fft.pdf) file.

Scope and Background ReadingThis session introduces the fast fourier transform (FFT) which is one of the most widely used numericalalgorithms in the world. It exploits some features of the symmetry of the computation of the DFT toreduce the complexity from something that takes order ( ) complex operations to somethingthat takes order ( ) operations.

!2 "( )!2

! log ! "(! log !)

The FFT is to be found in all manner of signal and image processing algorithms, and because it is moreefficient than the DFT, you will find it exploited in hundreds of signal processing applications.

As one example, it turns out that the computation of the convolution of two long DT sequences is moreefficient if the FFT of the two signals is taken, the product of the frequency spectra is computed, and theInverse DFT of the result is computed.

In this presentation, we will not go through the mathematical development of the FFT, please read section10.6 of Karris if you want the details. Here we will concentrate on the benefits to be gained by using theFFT and give some examples of its use in MATLAB.

AcknowledgementsThe material in this presentation and notes is based on Chapter 10(https://ebookcentral.proquest.com/lib/swansea-ebooks/reader.action?docID=3384197&ppg=405) of{cite} karris from the Required Reading List. The models of the FFT signal flow graphs and Simulinkblock diagrams are based on the presentation given in Section 12.5 of {cite} phillips .

Page 2: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 2 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Agenda

The inefficiency of the DFT

The FFT - a sketch of its development

An illustration of part of the FFT algorithm

FFT v DFT

Two examples

The inefficiency of the DFTConsider a signal whose highest frequency is 18 kHz, the sampling frequency is 50 kHz, and 1024samples are taken, i.e., .! = 1024

The time required to compute the entire DFT would be:

# = = 20.48 ms1024 samples50 ! samples per second103

To compute the number of operations required to complete this task, let us expand the N-point DFTdefined as:

$[%] = &[']!'=0

!"1( %'

!

Page 3: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 3 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Then$[0]$[1]$[2]

$[! " 1]

===#=

&[0] + &[1] + &[1] + # + &[! " 1]( 0! ( 0

! ( 0! ( 0

!

&[0] + &[1] + &[1] + # + &[! " 1]( 0! ( 1

! ( 2! ( !"1

!

&[0] + &[1] + &[1] + # + &[! " 1]( 0! ( 2

! ( 4! ( 2(!"1)

!

&[0] + &[1] + &[1] + # + &[! " 1]( 0! ( !"1

! ( 2(!"1)! ( (!"1)2

!

It is worth remembering that

= exp(") (0)) = 1.( 0!

2*!

Since is a complex number, the computation of any frequency component requires complex multiplications and complex additions

( +! $[,] !

!

complex arithmetic operations are required to compute any frequency component of 2! $[,].1

If we assume that is real, then only of the components are unique.&['] !/2 $[%]

Therefore we would require complex operations to compute the entire frequencyspectrum.

2! ! !/2 = !22

For our example, the -point DFT, would require complexoperations

! = 1024 = 1, 048, 57610242

These would have to be completed in 20.48 ms.

This may be possible with modern computing hardware, perhaps even in a mobile phone, but itseems impractical.

Fortunately, many of the terms in the computation are unity ( ).(! = ±1

Page 4: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 4 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Moreover, because the points are equally spaced points on the unit circle;( +!

And because is a power of 2, the points on the upper-half plane (range are the mirrorimage of the points on the lower-half plane range ;

! 0 < - < ** < - < 2*

Thus, there is a great deal of symmetry in the computation that can be exploited to simplify thecomputation and reduce the number of operations considerably to a much more manageable

operations .! !log23

This is possible with the algorithm called the FTT (https://en.wikipedia.org/wiki/Fast_Fourier_transform)(fast Fourier transform) that was originally developed by James Cooley(https://en.wikipedia.org/wiki/James_Cooley) and John Tukey (https://en.wikipedia.org/wiki/John_Tukey)and has been considerably refined since.

The Fast Fourier Transform (FFT)The FFT is very well documented, including in Karris, so we will only sketch its development and presentits main result. However, we will illustrate part of the algorithm to make concrete an idea of the efficiencyadvantage that the FFT has over the DFT that we have already seen.

Much of the development follows from the properties of the rotating vector.4

which results in some simplifications and mathematical short-cuts when is a power of 2.

= exp(" )(!)2*!

!

The most useful properties are:

( !!

( !/2!

( !/4!

( 3!/4!

=

=

=

=

exp(") !) = exp(")2*) = 1.2*!

exp(") ) = exp(")*) = "1.2*!

!2

exp(") ) = exp(")*/2) = ").2*!

!4

exp(") ) = exp(")3*/2) = ).2*!

3!4

Page 5: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 5 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

( ,!!

( ,!+.!

( ,2!

=

=

=

exp(") ,!) = exp(")2*) = 1, , = 0, 1, 2, …2*!

exp(") ,!) exp(") .) = 1. = .2*!

2*!

( .! ( .

!

exp(") ,) = exp(") ) = .2*2!

2*!

,2 ( ,/2

!

Representing$[0]$[1]$[2]

$[! " 1]

===#=

&[0] + &[1] + &[2] + # + &[! " 1]( 0! ( 0

! ( 0! ( 0

!

&[0] + &[1] + &[2] + # + &[! " 1]( 0! ( 1

! ( 2! ( !"1

!

&[0] + &[1] + &[2] + # + &[! " 1]( 0! ( 2

! ( 4! ( 2(!"1)

!

&[0] + &[1] + &[2] + # + &[! " 1]( 0! ( !"1

! ( 2(!"1)! ( (!"1)2

!

in matrix form:

= .

"

#

$$$$$$

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

$$[! " 1]

%

&

''''''

"

#

$$$$$$$

( 0!

( 0!

( 0!

#( 0

!

( 0!

( 1!

( 2!

#( !"1

!

( 0!

( 2!

( 4!

#( 2(!"1)

!

#####

( 0!

( !"1!

( 2(!"1)!

#( (!"1)2

!

%

&

'''''''

"

#

$$$$$$

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

$&[! " 1]

%

&

''''''

This is a complex Vandemonde matrix (https://en.wikipedia.org/wiki/Vandermonde_matrix) and it is morecompactly expressed as:

![%] = "[']#$

The algorithm developed by Cooley and Tukey is based on matrix decomposition methods, where thematrix is factored into smaller matrices, that is:

where is chosen as or .

#$ /= ##$ #1#2#3 #%

/ / = !log2 ! = 2/

Each row of the matrices on the right side of the decomposition, contains only two, non-zero terms, unityand .

And the DFT sequence is:

( ,!

![%] = # "['].#1#2#3 #%

Page 6: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 6 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

The FFT computation starts with matrix . It operates on producing a row vector, and eachcomponent of the row vector is obtained by one multiplication and one addition. This is because thereare only two non-zero elements on a given row, and one of those elements is unity. Since there are components of , there will be complex multiplications and complex additions.

#/ "[']

!"['] ! !

This new vector is then operated on by the matrix, then on and so on, until the entireoperation is completed.

#/"1 #/"2

It appears that the entire operation would require complex additions and also complex additions.

!/ = ! !log2! !log2

However, since , , and other simplifications, it is estimated that only about half ofthese, that is, total complex arithmetic operations are required by the FFT versus the required by the DFT .

= 1( 0! = "1( !/2

!! !log2 !2

5

Decomposition-in-Time FFT Algorithm

This development follows (Philips, et al., 2015). It is called the decomposition-in-time (DIT), radix-2, FFT.

It allows us to visualize the FFT as a block diagram (for simulation) or a signal flow graph (for ease ofdrawing).

We start from a 2-point FFT ( ), and work up to an 8-point FFT ( ) before generalizing theresult.

! = 2 ! = 8

We have implemented each algorithm in Simulink so we are able illustrate these structures withexecutable examples as we go.

2-Point DFT

$[,] = &['] = &[0] + $[1] , , = 0, 1.!'=0

1( ',

2 ( 0,2 ( 1,

2

Page 7: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 7 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Because and , we write= exp()0) = 1( 0,2 = exp(")*,) = ("1( 1,

2 ),

$[0]$[1]

==

&[0] + &[1];&[0] " &[1].

In general for the 2-point DFT, we have$[,] = &[0] + ("1 &[1].),

Page 8: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 8 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

An equivalent Simulink model in block diagram form is:

Let's See it in MATLAB

two_point_dft.slx (https://cpjobling.github.io/eg-247-textbook/dft/2/matlab/two_point_dft.slx)

In [1]: cd matlabclear allformat compact

In [2]: open two_point_dft

4-point DFT

The 4-point DFT is given by

$[,] = &['] = &[0] + &[1] + &[2] + &[3] .!'=0

3( ',

4 ( 0,4 ( 1,

4 ( 2,4 ( 3,

4

Page 9: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 9 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

As a result of the periodicity of the weighting factor, we can simplify this expression:( ',

!( 0,

4( 1,

4( 2,

4( 3,

4

=====

exp(")(2*/!)',);1;exp(")(*/2),) = (") ;),

exp(")*,) = ("1 ;),

= ("1 .( 2,4 ( 1,

4 ),( 1,4

Using these results, we write$[,]$[,]

==

&[0] + &[1] + &[2]("1 + &[3]("1 ,( 1,4 ), ),( 1,

4

[&[0] + &[2]("1 ] [&[1] + &[3]("1 ] .), ), ( 1,4

To clarify the next step, we define two new variables[']&0[']&1

==

&[2'], ' = 0, 1;&[2' + 1], ' = 0, 1.

Then,$[,] = [ [0] + [1]("1 ] + [ [0] + [1]("1 ] .&0 &0 ), &1 &1 ), ( 1,

4

The factors in brackets in this equation can be recognized as 2-point DFTs:[%]$0[%]$1

==

[0] + [1]("1 , % = 0, 1;&0 &0 )%

[0] + [1]("1 , % = 0, 1.&1 &1 )%

Note that and are periodic; for example,

and

[,]$0 [,]$1[2] = [0] + [1]("1 = [0]$0 &0 &0 )2 $0

[3] = [0] + [1]("1 = [1]$1 &1 &1 )3 $1

The 4-point DFT then is$[0]$[1]$[2]$[3]

====

[0] + [0] = [0] + [0];$0 $1 ( 1(0)4 $0 $1

[1] + [1] = [1] + [1] ;$0 $1 ( 1(1)4 $0 $1 ( 1

4[0] " [0] = [0] " [0];$0 $1 ( 1(2)

4 $0 $1

[1] " [1] = [1] + [1] .$0 $1 ( 1(3)4 $0 $1 ( 1

4

Page 10: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 10 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

We see that the 4-point DFT can be computed by the generation of two 2-point DFTs, followed by arecomposition of terms as shown in the signal flow graph below:

In other words,

[4-point DFT of ] = [2-point DFT of ] + [2-point DFT of ].&['] [']&0 ( 1,4 [']&1

SIMULINK Model of 4-Point DFT

four_point_dft.slx (https://cpjobling.github.io/eg-247-textbook/dft/2/matlab/four_point_dft.slx)

In [3]: open four_point_dft

In Class Example 1Use four-point DIT FFT to confirm that the DFT of the sequence

is

&['] = [1, 2, 3, 4]

$[%] = [10, "2 + )2, "4, "2 " )2].

Page 11: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 11 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

8-point DFT

$[,] = &['] .!'=0

7( ',

8

After some manipulation, not reproduced here, it can be shown that the 8-point DFT is the recombinationof two, 4-point DFTs that operate on the even and odd numbered values in the sequence respectively.

&[']

Page 12: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 12 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Signal flow graph of 8-point DFT

SIMULINK Model of 8-Point DFT

eight_point_dft.slx (https://cpjobling.github.io/eg-247-textbook/dft/2/matlab/eight_point_dft.slx)

In [4]: open eight_point_dft

Page 13: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 13 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

N-Point, radix-2 DIT FFT

In general, the -point, radix-2 DIT FFT is computed as the recomposition of two -point FFTs) asshown in the buterfly diagram below

! (!/2)

Decomposition-in-Frequency FFTAnother approach to forming the FFT is the so-called decomposition in frequency (DIF) FFT.

We will not cover it's development in detail (see Karris and Phillips et al.) if you want to follow it through.

We instead illustrate the final result for the four-point DIF FFT.

Page 14: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 14 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Signal flow graph for 4-point DIF FFT

Note that the structure is a 4-point decompostion followed by two 2-point FFTs.

Also note that it is frequency that is the input to the DFT stage.[,]$'

In Class Example 2Use four two-point DIF FFT to confirm that the DFT of the sequence

is

&['] = [1, 2, 3, 4]

$[%] = [10, "2 + )2, "4, "2 " )2].

Page 15: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 15 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

SIMULINK Model of 4-Point DIF FFT

four_point_dif.slx (https://cpjobling.github.io/eg-247-textbook/dft/2/matlab/four_point_dif.slx)

In [5]: open four_point_dif

8-Point DIF FFTI have created a Simulink model of the 8-point DIF FFT. I will create a signal flow graph to go with it atsome point in the future.

SIMULINK Model of 4-Point DIF FFT

eight_point_dif.slx (https://cpjobling.github.io/eg-247-textbook/dft/2/matlab/eight_point_dif.slx)

Page 16: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 16 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Efficiency of the FFTWether we implement it as a Decomposition-in-Time (DIT) or a Decomposition-in-Frequency (DIF), theFFT ends up having approximately multiplications and a similar number of complexadditions or subtractions.

In other words, complex arithmetic operations.

As complex arithmetic, particularly multiplication, is very expensive, this is a great saving over the DFTwhich has of order operations.

(!/2) (!)log2

(!) (!)log2

!2

DFT and FFT ComparisonsUnder the assumptions about the relative efficiency of the DFT and FFT we can create a table like thatshown below:

DFT FFT FFT/DFT

N %

8 3 64 24 37.5

16 4 256 64 25

32 5 1,024 160 15.6

64 6 4,096 384 9.4

128 7 16,384 896 5.5

256 8 65,536 2,048 3.1

512 9 261,144 4,608 1.8

1024 10 1,048,576 10,240 1

2048 11 4,194,304 22,528 0.5

!log2 ! 2 ! log2!

As you can see, the efficiency of the FFT actual gets better as the number of samples go up!

However, there are other costs, such as the data storage needed for intermediate steps, that need to betaken into account as well. For example, an 8-point FFT requires only a 3 stage decomposition, with eachstage needing storage for 8 complex numbers. That is 24 in all. Whereas a 2048 sequence will require 11stages, storing 2048 values each. That is a total of 22,528 complex values .6

In Class Demonstrations

Page 17: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 17 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

FFT in MATLABThe FFT algorithm is implemented, in MATLAB, as the function fft . We will conclude the class byworking through Exercises 6 and 7 from section 10.8 of Karris.

Example 3Plot the Fourier transform of the rectangular pulse shown below, using the MATLAB fft func-tion.Then, use the ifft function to verify that the inverse transformation produces the rectangular pulse.

FFT for Example 3

The rectangular pulse can be produced like so

Page 18: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 18 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

In [6]: x = [linspace(-2,-1,50) linspace(-1,1,100) linspace(1,2,50)];y = [linspace(0,0,50) linspace(1,1,100) linspace(0,0,50)];plot(x,y)

and the FFT is produced as

Page 19: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 19 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

In [7]: plot(x, abs(fft(y)))

unwind

Page 20: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 20 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

In [8]: plot(x, abs(fftshift(fft(y))))

The inverse FFT is obtained with

Page 21: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 21 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

In [9]: plot(x, ifft(fft(y)))

Example 4

Page 22: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 22 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

FFT Example 4

The triangular pulse is obtained with

In [10]: x = linspace(-1,1,100);y = [linspace(0,1,50) linspace(1,0,50)];plot(x,y)

and the FFT is obtained with

Page 23: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 23 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

In [11]: plot(x, abs(fftshift(fft(y))))

The inverse FFT is obtained with

Page 24: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 24 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

In [12]: plot(x, ifft(fft(y)))

SummaryThe inefficiency of the DFTThe FFT - a sketch of its developmentAn illustration of part of the FFT algorithmFFT v DFTTwo examples

HomeworkRead the rest of Chapter 10 of Karris from page 10.9 and make your own notes on the implementation ofthe FFT.

Page 25: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 25 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

The End?This concludes this module.There is some material that I have not covered, most notably is a significant amount of additionalinformation about Filter Design (including the use of MATLAB for this) in Chapter 11 of Karris.

ReferencesSee Bibliography (/zbib).

Footnotes1. Note: addition of two complex numbers so requires 2

floating-point additions; multiplication requires fourfloating-point multiplications and two additions.

In MATLAB, complex numbers are represented internally as two 64 bit floating point operations soeach complex operation is expensive both in terms of computing time and working memory space.And the result of an N-point DFT will require twice the memory of the original sequence, assumingthat it is stored as floating point real numbers, considerably 16 times the storage is needed if theoriginal sequence is the result of sampling by, say, an 8 bit ADC.

Of course, modern 64 bit mirocprocessers have hardware support for floating point operations andso these operations take a minumum number of machine cycles. Digital Signal Processors andGraphic Processing Units, probably have hardware support for complex arithmetic too. Nonethess,complex arithmetic is an expensive operation, so any simplifications we can make will be valuable.

2. Even if we do not have a real sequence, we only need to compute the first values of thespectrum because the sequence for from are complex conjugates, inthe reverse order, of the sequence of for . This is easy to prove by looking at thegeometry of the unit circle in the z-plane.

3. If , complex operations.4. The Inverse FFT (IFFT) follows by noting that the rotation vector used in its computation is the

complex conjugate

5. Karris goes further in showing how the decomposition used to implement the FFT can be further beunderstood by considering even and odd decompositions. This is also the approach taken byPhillips et al. reproduced here. You'll also find that most text books on Digital Signal Processing willcover the FFT and give more or less understandable presentations of the way the algorithm works.

6. A complex number in MATLAB is 2 floating point doubles or 128 bits. So a 2048 "bin" FFT needsstorage in RAM for approximately Mbit ( kByte) of data.

(2 + )3) + (4 + )5) = (2 + 3) + )(3 + 5)(2 + )3)(4 + )5) = (24 " 35) + )(25 + 34)

!/2$[,] !/2 + 1 < , % ! " 1$[,] 0 % , < !/2

! = 1024 ! ! = 1024 ! 10 = 10, 240log2

.( "1!

22, 528 ! 128 = 2.9 260

Page 26: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 26 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Solutions

Example 1From the mathematical development and signal flow graph shown earlier:

Thus,

Q.E.D.

[0]$0[1]$0[0]$1[1]$1

====

&[0] + &[2] = 1 + 3 = 4;&[0] " &[2] = 1 " 3 = "2;&[1] + &[3] = 2 + 4 = 6;&[1] " &[3] = 2 " 4 = "2.

$[0]$[1]$[2]$[3]

====

[0] + [0] = 4 + 6 = 10,$0 $1[1] + [1] = "2 + ("))("2) = "2 " )2,$0 ( 1

4 $1

[0] " [0] = 4 " 6 = "4,$0 $1[1] " [1] = "2 " ("))("2) = "2 + )2.$0 ( 1

4 $1

Example 2After decomposition we have:

Hence, after 2-point FFT:

Q.E.D.

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

====

&[0] + &[2] = 1 + 3 = 4;[&[1] " &[3]] = 2 + 4 = 6;( 0

4&[0] " &[2] = 1 " 3 = "2;

[&[1] " &[3]] = ")[2 " 4] = )2.( 14

$[0]$[1]$[2]$[3]

====

[0] + [1] = 4 + 6 = 10,$1 $1[0] + [1] = "2 + )2,$2 $2[0] " [1] = 4 " 6 = "4,$1 $1[0] " [1] = "2 " )2.$2 $2

Page 27: The Fast Fourier Transform · An illustration of part of the FFT algorithm FFT v DFT Two examples The inefficiency of the DFT Consider a signal whose highest frequency is 18 kHz,

20/07/2020, 19:59fft

Page 27 of 27http://127.0.0.1:8888/nbconvert/html/dft/2/fft.ipynb?download=false

Example 3See script fft_ex1.m (https://cpjobling.github.io/eg-247-textbook/dft/2/matlab/fft_ex1.m).

Example 4See script fft_ex2.m (https://cpjobling.github.io/eg-247-textbook/dft/2/matlab/fft_ex2.m).