Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Department of Electrical and Electronics Engineering

Let's look at these commands one-by-one:


EEM 3005 Signals & Systems Practice #7 f = fftshift(fft(x)): Here we are calculating the Fourier series coefficients. The
command fftshift modifies the output of fft so that the zero-frequency component
is in the middle of the vector f.
N = length(f): We will need the length of f to do some normalization below.

n = -(N-1)/2:(N-1)/2: Vector n contains the indices of vector f, although these


1 Introduction aren't the actual frequency indices. Those are in w.
This assignment gives Matlab examples for the material covered in Lecture Notes. w = 2*pi*n/N/dt: These are the frequency indices for each of the elements of f.
Commands indicated by the >> should be typed in the Matlab Command Window.
This exercise builds on the previous Matlab exercises, so please have a look at them if f = f ./ N: We normalize by a factor N so that the output of fft agrees with the
you have not already done so. coefficients as defined in the Lecture Notes

stem(w,real(f)): We plot the real part of the spectrum.


2 The Continuous Fourier Transform
axis([-10 10 -1 1]): Zoom in on the portion of the spectrum of interest to us.
In thıs practıce we wıll discuss the continuous Fourier transform. Matlab does not
Now that we have understood the code used to get the Fourier transform
support continuous-time signals. Thus at first glance it might seem rather difficult to
approxima-tion, let's examine the results.
calculate continuous Fourier transforms numerically in Matlab. However, we will
examine a technique which will give a good approximation!
2.2 Some experiments to try
2.1 Approximating the Fourier Transform You should try modifying the Matlab code above to look at:
As we discussed before, we can approximate a continuous-time signal using a very 1. Non-integer periods: what happens if we don't use an integer number of periods
finely-sampled discrete version (i.e. by using a very small step size). Let's do this for
of the signal? Try changing the time vector t to (for example) 2.5 periods . How
the function cos(t):
does this affect the Fourier transform output? What about if you
> dt = 0.001;
use 2.3 periods? What effect are you seeing here?
> t = 0:dt:2*2*pi;
> x = cos(t); 2. Fourier transform of sin(t): Try calculating the Fourier transform for sin(t).
This creates a discrete-time approximation to cos(t) using a step size of 0.001 (Hint: we expect that the coefficients will be imaginary, so you should modify the
seconds, for two periods of the function (it's period is 2 ). Have a look at the signal: code accordingly).
>> plot(t,x);
Now, we will use the Matlab fft command in order to calculate the Fourier series coeffi- 2.3 Non-periodic signals
cients of the signal, which will give us an approximation to the Fourier transform: Now let's look at the aperiodic square wave :
> f = fftshift(fft(x));
> N = length(f);
> n = -(N-1)/2:(N-1)/2;
> w = 2*pi*n/N/dt;
> f = f ./ N;
> stem(w,real(f));
> axis([-10 10 -1 1]);
> dt = 0.001; Now that we know what output to expect, let's try using the convolution property (
> t = 0:dt:10;
> Nx = length(t); > f = fft(x,Ny);
> x = [ones(1,1/dt)]; > g = f.*f;
> x = [x zeros(1,Nx-length(x))]; > z = ifft(g,Ny);
> tz = ty;
Take the Fourier transform as we did before: > plot(tz,z);
f = fftshift(fft(x)); You should obtain the same result as you did before from the convolution method.
N = length(f); (The extra parameter to fft and ifft results in the vectors having Ny points, the correct
n = -(N-1)/2:(N-1)/2; number we need to compare with the time-domain convolution case).
w = 2*pi*n/N/dt; To convince yourself further, try doing this with other signals, such as the
f = f ./ max(f); convolution of cos(t) and a square wave:
stem(w,real(f));
axis([-20 20 -1 1]); > dt = 0.001;
> tx = 0:dt:2*2*pi;
What do you see? Now, try changing the length of the time window, > Nx = length(tx);
i.e.: > x1 = [ones(1,floor(Nx/2)) zeros(1,ceil(Nx/2))];
> x2 = cos(tx);
>> t = 0:dt:20;
First, the time-domain convolution:
Re-calculate the Fourier coefficients and re-plot them. Try this for
several larger window sizes. You should see the stem plot starting > y = conv(x1,x2);
to look like a continuous-time function as you increase the time- > Ny = length(y);
domain window (and thus increase the resolution in the frequency > ty = 0:dt:dt*(Ny-1);
> plot(ty,y);
domain).
Now, the frequency-domain multiplication:

3 The Convolution Property > f1 = fft(x1,Ny);


> f2 = fft(x2,Ny);
We have learned that the time-domain and Fourier-domain have a relationship > g = f1.*f2;
whereby convolution in one domain is equivalent to multiplication in the other domain. > z = ifft(g);
First, let's create an approximation of a continuous-time square wave: > tz = ty;
> plot(tz,z);
> dt = 0.001;
> t = 0:dt:10; Again, you will obtain the same results.
> Nx = length(t);
> x = [ones(1,floor(N/2)) zeros(1,ceil(N/2))];
Now, let's calculate the time-domain convolution of two of these square waves:
> y = conv(x,x);
> Ny = length(y);
> ty = 0:dt:dt*(Ny-1);
> plot(ty,y);

You might also like