Fourier Transform -...

22
Fourier Transform Prepared by :Eng. Abdo Z Salah

Transcript of Fourier Transform -...

Fourier Transform

Prepared by :Eng. Abdo Z Salah

What is Fourier analysis??

Fourier Analysis is based on the premise that any arbitrary signal can be constructed using a bunch of sine

and cosine waves. See this crazy signal? It looks more like a conglomeration of random points.

Believe it or not, we can recreate that signal using a lot of sine and cosine waves (more specifically, we

would need an infinite number of waves to make this happen)!

So Why is This Useful?

All signals inherently have characteristics such as frequency, phase, and amplitude. In applications such

as signal processing, image processing, communications, these characteristics are vital and offer

invaluable insight. In the time domain, it is difficult to ascertain these qualities. But in the frequency

domain, it is much easier.

How do we go from the time domain to the frequency domain? The process by which this is done is called the Fourier transform. By representing a signal as the sum of

sinusoids, we are effectively representing that same signal in the frequency domain.

Okay, so it Sounds Somewhat Useful, but can You Give us a Practical

Example?

Let’s take another look at the crazy signal I showed you earlier:

This is a signal of a building’s response during an earthquake. Now, looking at that curve, there isn’t very

much useful information there. But lets take the Fourier transform of that and see what we get (see graph

below). Once we do this, we will begin to get a better idea on why Fourier analysis is so valuable.

Okay, so I took the Fourier Transform of the Signal, now What?

If you notice, there are large spikes at specific frequencies. What does this mean? Those are the resonant

frequencies of the building. At those frequencies, the building will sustain the most damage. This is useful

information to know, because builders can modify the building so that these resonant frequencies are

mitigated. Using this kind of analysis, we can build structures that are able to withstand earthquakes. In

areas where earthquakes are a real concern, this is of utmost importance.

This simple introduction from http://blinkdagger.com/

Now we will derive the Fourier transform ? Introduction:

Fourier series and the Fourier transform play a vital role in many areas of engineering such as

communications and signal processing. These representations are among the most powerful and most

common methods of analyzing and understanding signals. A solid understanding of Fourier series and the

Fourier transform is critical to the design of filters and is beneficial in understanding of many natural

phenomena.

In the last Lab we see that any periodic signal that meet the condition of the Fourier series can be

represented in terms of cosines and sins that are related in harmonic or by a complex exponential. We

called the plot of Dn as the line spectrum of the function which make an indication about the frequency

components that the function consists of .

In this Lab we will see hoe the fourier series can be use to represent the aperiodic signal .

Aperiodic signal representation by Fourier integral

In order to represent aperiodic function in the frequency domain we will first consider that we

have a periodic function with period T and then when the period T get larger so that T goes to

the infinity we observe that we have aperiodic function ,so our analysis will start with periodic

function then increase the period until we reach the aperiodic function .

consider we have a pulse train as show in the figure1 with period T

T

-10 -8 -6 -4 -2 0 2 4 6 8 100

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

-20 0 20 40 60 80 100 120 1400

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

Now if you compute the Fourier coefficient Dn of the periodic function

( ) ojnw t

n

n

f t D e

0

0

2

02

1( ) o

T

jnw tn

T

D f t eT

for our signal

sin( )5 5sin ( )o

n o

o o o

nwD c nw

T nw T

now we will plot Dn and note that Dn is real so we will plot the magnitude and the phase in the

same figure

-10 -8 -6 -4 -2 0 2 4 6 8 10

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

nw

Dn

The line spectrum

the distance between

the two lines is w

now we will see what will happen if we increase T

5sin ( )n o

o

D c nwT

-25 -20 -15 -10 -5 0 5 10 15 20 25-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

nw

Dn

The line spectrum withT=4

-40 -30 -20 -10 0 10 20 30 40-0.1

-0.05

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

nw

Dn

The line spectrum withT=16

-100 -80 -60 -40 -20 0 20 40 60 80 100-0.02

-0.01

0

0.01

0.02

0.03

0.04

0.05

0.06

0.07

0.08

nw

Dn

The line spectrum withT=64

-300 -200 -100 0 100 200 300-5

0

5

10

15

20x 10

-3

nw

Dn

The line spectrum withT=256

-40 -30 -20 -10 0 10 20 30 40-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

nw

Increasing T ,decreasing the amplitude of Dn

T=4

T=8

T=12

T=16

T=20

So what we see is that as we increase T or decrease the frequency the amplitude of the line

spectrum decrease and the line get close and close to each other .the figure below show the

decreasing of the amplitude when T increase

so when T the amplitude 0oand w and the spacing between the lines go to zero .

so let ow w since w is infinitesimal .

now we need another way in order to extract a meaningful information from Dn since it is go to

zero as we increase the period of the function .

0 0

0 0

0

2 2

02 2

1( ) ( )o o

T T

jn w t jn w tn n

T T

TD f t e D f t eT

note that

2o

n n

wf

D D

this quantity is called the Coefficient Density

since 0T n w ww

where W is a continues variable that at every point of the spectrum there is a value of Dn which

is infinitesimal,

0 this is a continues function of w and called X(w)( ) jwtnTD f t e

X(w) ( ) jwt FourierTransformf t e

so what we have here is a representation of the an aperiodic signal in the frequency domain .now

in the modify the equation of f(t)

0

1( )

22

( )

2

0

1 1( ) lim ( ) ( )

2 2

o o

o

jn w t jn w tnn

n n

n

jnw t jwt

ww

Df t D e e w

w

DX w

w

w

f t X w e w X w e dw

now we are going to plot ( ) ojnw tF w e to show that the summation goes to the integral

2 4 6 8 10 12 14 16-2-4

2

4

-2

-4

-6

2 4 6 8 10 12 14 16-2-4

2

4

-2

-4

-6

Y=5·sin(X)

X

Δw

1( ) ( )

2

jwt called the Fourier Integral

or the Fourier Inver

f t X

s

w e dw

e

We have now succeeded in representation an aperiodic signal x(t) by a Fourier integral rather

than a Fourier series .This integral is basically a Fourier series (in the limit ) with fundamental

frequency goes to zero

1( ) [ ( )] ( ) [ ( )]X w x t x t X w

Investigate the Scaling Property

1( ) ( )

wx at X

a a

Note that compression in time by factor a means mean that the signal is varying faster by factor

a and to synthesize such a signal the frequencies of its sinusoidal components must be increased

by a factor a implying that its frequency spectrum is expanded by factor a . similarly a signal

expand in time varies more slowly ,hence the frequency of its components are lowered implying

that the its spectrum is compressed

The graph confirm the reciprocal relationship between signal duration and spectral bandwidth

:time compression causes spectral expansion and time expansion causes spectral compression .

Parseval's Theorem and essential bandwidth ?

Parseval's Theorem concisely relates energy between the time domain and the frequency domain

2 21

( )2

dt tx X w dw

this is too easily verified with Matlab .For example a unit amplitude pulse x(t) with duration tau

has energy xE ,Thus

2

d 2x w w

letting tau=1 the energy of X(w) is computed using the quad function .

>> X_squared = inline('tau.*sinc(tau.*w/(2*pi)).^2','w','tau');

quad(X_squared,-1e6,1e6,[],[],1)

ans =

6.2817

-10 -5 0 5 10

0

0.5

1

1.5

x(

)

Normal(=1)

Compressed(=.5)

Expanded(=2)

Although not perfect ,the result of the numerical integration is consistent with the expected value

of 2 6.2832

,in the quad the tow brackets are for special parameter and we do not concern it , the last

parameter is 1 which the value of tau and it should be inserted because of the integration depend

on it .

Essential Bandwidth ?

The spectra of all practical signals extend to infinity .however because the energy of any

practical signal is finite ,the signal spectrum must approach zero as w ,so most of the

energy is concentrating with a limited band B and the energy contribution by the component

beyond B is negligible we can therefore suppress the signal spectrum beyond B Hz with a little

effect on the signal energy and shape ,so the essential bandwidth is the portion of a signal

spectrum in the frequency domain which contains most of the energy of the signal. Say for

example 95% or any ratio according to your systems

Consider for example finding the essential bandwidth W ,in radians per second ,that contain s

fraction β of the energy of the square pulse x(t).That is ,we want to find W such that

21( )

2

W

W

X w dw

Algorithm for finding the essential bandwidth

function [W,CE]=EBW(tau,beta,tol)

start at W=0

define the desired energy =Beta*tau

define a step with any initial value

define the relative error between the desired value and the computed value

relerrDesired E Computed E

Desired E

>> X_squared = inline('tau.*sinc(tau.*w/(2*pi)).^2','w','tau');

CE=quad(X_squared,-W,W,[],[],tau)

1-compute CE

2-compute relerr

W too small that relerr is positive

then increase W by a step .

W too larg that the step is large

then decrase the step by a fraction

and then decrease the step

recompute 1 and 2

while (abs(relerr)>tol)

function [W,CE] = EBW(tau,beta,tol) % Function M-file computes essential bandwidth W for square pulse. % INPUTS: tau = pulse width % beta = fraction of signal energy desired in W % tol = tolerance of relative energy error % OUTPUTS: W = essential bandwidth [rad/s] % CE = Energy contained in bandwidth W W = 0; step = 2*pi/tau; % Initial guess and step values X_squared = inline('tau.*sinc(tau.*w/(2*pi)).^2','w','tau'); DE = beta*tau; % Desired energy in W relerr = (DE-0)/DE; % Initial relative error is 100 percent while(abs(relerr) > tol), if (relerr>0), % W too small W=W+step; % Increase W by step elseif (relerr<0), % W too large step = step/2; W = W-step; % Decrease step size and then W. end CE = 1/(2*pi)*quad(X_squared,-W,W,[],[],tau);%computed energy relerr = (DE - CE)/DE; end

Fourier Transform and Inverse Fourier in Matlab

2

( ) tf t e syms t w

x=exp(-t^2);

fourier(x)

1( )

1X w

jw

syms n

X=1/(1+j*w);

ifourier(X,n)

( ) ( )tf t e u t syms t w

x=exp(-t)*heaviside(t);

X=fourier(x,w)

( )t

f t te

syms x u;

f = x*exp(-abs(x));

fourier(f,u)

Introduction to FFT (Fast Fourier Transform)

we will discuss how to use the fft (Fast Fourier Transform) command within MATLAB.

A Simple Example

1. Let’s start off with a simple cosine wave, written in the following manner:

( ) 2sin(2 )oy t f t

2. Next, let’s generate this curve within matlab using the following commands:

fo = 4; %frequency of the sine wave

Fs = 100; %sampling rate

Ts = 1/Fs; %sampling time interval t = 0:Ts:1-Ts; %sampling period

n = length(t); %number of samples

y = 2*sin(2*pi*fo*t); %the sine curve

%plot the cosine curve in the time domain

plot(t,y)

xlabel('time (seconds)') ylabel('y(t)') title('Sample Sine Wave')

grid

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

time (seconds)

y(t)

Sample Sine Wave

3. When we take the fft of this curve, we would ideally expect to get the following

spectrum in the frequency domain (based on fourier theory, we expect to see one

peak of amplitude 1 at -4 Hz, and another peak of amplitude 1 at +4 Hz):

4. So now that we know what to expect, let’s use MATLAB’s built in fft command

to try to recreate the frequency spectrum:

Y = fft(y); %take the fft of our sin wave, y(t) stem(Y); %use abs command to get the magnitude %similary, we would use angle command to get the phase plot! xlabel('Sample Number') ylabel('Amplitude') title('Using the Matlab fft command') grid

0 10 20 30 40 50 60 70 80 90 100

-150

-100

-50

0

50

100

Sample Number

Using the Matlab fft command

This doesn’t quite look like what we predicted above. If you notice, there are a couple of

things that are missing.

The x-axis gives us no information on the frequency. How can we tell that the peaks are in the

right place?

The amplitude is all the way up to 100

The spectrum is not centered around zero and is not even

You can see that a problem exists due to the fact that the output of the FFT function is a

complex valued vector. MATLAB plots complex numbers on the two-dimensional complex

plane, which is not the plot you are trying to generate. What is usually significant in

communications is the magnitude of the frequency domain representation. You can plot the

magnitude of the FFT by using MatLab's abs function:

>> plot ( abs ( Y ) )

Matlab sets axes automatically unless a user defines them. To define the x- and y-axis in order

to see the plot in detail:

axis([0,100,0,120])

Fs = 1/Ts is the sampling rate given in sample per second

Hence that highest possible analogue frequency is Fmax = Fs /2

Now the graph looks like a frequency domain plot. However it still does not look like what

we would expect to see. This is because MATLAB presents frequency components from f = 0

to f = fs (i.e. from DC to the sampling frequency). However, we are used to seeing the plots

range from f = -fs/2 to f = +fs/2. This problem can be overcome by using the fftshift function.

To get help on this function type:

>> help fftshift

Plot the magnitude using the fftshift function to move the dc component to the center of the

display:

>> plot ( abs ( fftshift ( Y ) ) )

Now the plot is starting to look like the expected Fourier transform. However, the x-axis is

still not correct. The x-axis should be scaled to display frequencies from -fs/2 to fs/2.

>>f=-fs/2:fs/length(y):fs/2-fs/length(y);

so the complete code Y=fft(y);

Y=Y/length ( Y ) ;

f=-Fs/2:Fs/length(y):Fs/2-Fs/length(y);

stem (f, fftshift ( abs ( Y ) ) )

FFT using the oscilloscope As part of the experiment, the FFT has to be obtained using the oscilloscope. In order to obtain the FFT, the following steps should be carried out.

First the time domain signal should be set properly by the following steps:

a. Press AUTOSET to display the time domain waveform.

b. Position the time domain waveform vertically at center of the screen to get the “true” DC value.

c. Position the time domain waveform horizontally so that the signal of interest is contained in the center eight divisions.

d. Set the YT waveform SEC/DIV to provide the resolution you want in the FFT waveform. This decides how high the frequency content of the transform will be. The smaller the time scale used the higher the frequency content.

Then the FFT can be performed as follows:

e. Locate the math button on the front panel of the oscilloscope.

f. On pressing it you will enter the Math menu

g. In function choose fft.

h. The following screen will appear. (Clearly the waveform in your case will be different.)

i.then use the curser in order to compute the frequency

For all FFT’s in this experiment always use the Hanning window, as it is best suited among the given options for a periodic signal. A windowing function is basically a function used to cut out a part of the signal in time domain so that an FFT can be carried out on it. Thus basically it is multiplication by some kind of rectangular pulse in time domain, which implies convolution with some kind of a sinc in frequency domain. Using a windowing function affects the transform but is the only practical method for obtaining it.

Lab homework For the following function 1-calculate the Fourier transform (by hand calculations)

( ) ( )atf t e u t

2-plot the spectrum for different values of a (.5,1,2,3) and comment on your results ?

3-calculate the total energy of the signal

4- write a function that computes the essential bandwidth and computes the energy in that

bandwidth for 95% of the total energy.

5- for the following functions plot the functions and use fft to plot the spectrum of the function ?

. ( ) sin(2 8 )

. ( ) sin(2 8 ) cos(2 16 )

. ( ) sin(2 10 ) 5cos(2 20 ) 0.2randn ( 1, length ( t ) );

a y t t

b y t t t

c y t t t

note :0.2*randn ( 1, length ( t ) ); is AWGN(Additive White Gaussian Noise) to the time

domain signal in order to make the output more like the practical output of oscilloscope: Comment the results