Sie sind auf Seite 1von 12

Priyanka Jillella

OPTI 512L
Lab#1 Discrete Fourier Transform I

1. The Fourier transform of a Gaussian is a Gaussian. Generate the following Gaussian random vector,
x = linspace(-15,15,257);
x = x(1:256);
y = exp(-.5 * x.2);
Now, take the FFT, i.e.,
Y = fft(y);
and plot the real part of your result. Explain why this doesnt look like a Gaussian. Fix the problem.

>> x = linspace(-15,15,257);
x = x(1:256);
fx = exp((-.5)*(x.^2));
figure(1);
plot(real(fx));
xlabel('x');
ylabel('f(x)');
title('Gaussian function');

>> F_fx = fft(fx);


figure(2);
plot(real(abs(F_fx)));
xlabel('N');
ylabel('real (Fourier f(x))');
title('FFT of Gaussian function');

Answer: When the region between 0 and fs (sampling frequency) is examined, it


can be seen that there is even symmetry around the center point, 0.5fs, the
Nyquist frequency. This symmetry adds redundant information. Since a real
signal should have a transform magnitude that is symmetrical for positive
and negative frequencies, instead of having a spectrum that goes from 0 to
fs, it would be more appropriate to show the spectrum from fs/2 to fs/2.
This can be accomplished by using Matlab's ifftshift function.

1
Priyanka Jillella

>> x = linspace(-15,15,257);
x = x(1:256);
fx = exp((-.5)*(x.^2));
Ffx = fft(fx);
Ffx_mod = fftshift(abs(Ffx));
delx = x(2)-x(1);
xi = linspace(-1/(2*delx),1/(2*delx),257);
xi = xi(1:256);
figure(3);
plot(xi,(real(Ffx_mod)));
xlabel('Frequency (1/\deltax)');
ylabel('real (Fourier f(x))');
title('FFT of Gaussian function
(fftshifted)');

2
Priyanka Jillella

2. Generate discritized versions of the following functions and plot the results of their FFTs (just the real part).
a) Rect function
(b) sinc function
(c) f(x) = 1.
Use vectors of length 256 elements for this problem.

a) Rect Function

>>x=linspace(-127,128,256);
fx=zeros(size(x));
fx(abs(x)<64)=1;
figure(1);
plot(x,fx);
xlabel('x');
ylabel('f(x)');
title('Rect Function');

>>Ffx=fft(fx);
Ffx2 = fftshift(abs(Ffx));
delx = x(2)-x(1);
xi = linspace(-1/(2*delx),1/(2*delx),257);
xi = xi(1:256);
figure(2);
plot(xi,(real(Ffx2)));
xlabel('Frequency 1/\deltax');
ylabel('real {FFT f(x)}');
title('FFT of Rect function');

3
Priyanka Jillella

b) Sinc Function

>>x=linspace(-50,50,256);
fx=sinc(x);
figure(3);
plot(x,fx);
xlabel('x');
ylabel('f(x)');
title('Sinc Function');

>>Ffx=fft(fx);
Ffx2 = fftshift(abs(Ffx));
delx = x(2)-x(1);
xi = linspace(-1/(2*delx),1/(2*delx),257);
xi = xi(1:256);
figure(4);
plot(xi,(real(Ffx2)));
xlabel('Frequency 1/\deltax');
ylabel('real {FFT f(x)}');
title('FFT of Sinc function');

4
Priyanka Jillella

b) Constant

>>x=linspace(-127,128,256);
fx=ones(size(x));
figure(5);
plot(x,fx);
xlabel('x');
ylabel('f(x)');
title('Constant');

>>Ffx=fft(fx);
Ffx2 = fftshift(abs(Ffx));
delx = x(2)-x(1);
xi = linspace(-1/(2*delx),1/(2*delx),257);
xi = xi(1:256);
figure(4);
plot(xi,(real(Ffx2)));
xlabel('Frequency 1/\deltax');
ylabel('real {FFT f(x)}');
title('FFT of Constant');

5
Priyanka Jillella

3. Generate a Rect function. Use the Fourier-convolution theorem to convolve this Rect with itself 1, 2, and 3
times. Plot the results. Make sure your Rect function isnt too wide.

>>%% Rect Function


x=linspace(-127,128,256);
fx=zeros(size(x));
fx(abs(x)<64)=1;
figure(1);
plot(x,fx);
xlabel('x');
ylabel('f(x)');
title('Rect Function');

>>Ffx=fft(fx);
Ffx2_1 = Ffx.*Ffx; % convolving with
itself one time
fx2_1=ifftshift(abs(Ffx2_1));
figure(2);
plot(x,real(fx2_1));
xlabel('x');
ylabel('f(x)(*)f(x)');
title('Rect function convolved with itself
(1 time)');

>>Ffx2_2=Ffx2_1.*Ffx; % convolving with


itself second time
fx2_2=ifftshift(abs(Ffx2_2));
figure(3);
plot(x,real(fx2_2));
xlabel('x');
ylabel('f(x)(*)f(x)(*)f(x)');
title('Rect function convolved with itself
(2 times)');

6
Priyanka Jillella

>>Ffx2_3=Ffx2_2.*Ffx; % convolving with


itself second time
fx2_3=ifftshift(abs(Ffx2_3));
figure(4);
plot(x,real(fx2_3));
xlabel('x');
ylabel('f(x)(*)f(x)(*)f(x)(*)f(x)');
title('Rect function convolved with itself
(3 times)');

7
Priyanka Jillella

4. Using the coordinates x = linspace(-15,15,257); x = x(1:256);, generate one dimensional Gaussians with
standard deviations varying from 0.1 to 10. Take the DFT of each of these vectors and plot the real part of your
results. Explain your results. Especially focus on the behavior of your results as you varied and standard
deviation and the weird results you should see when the standard deviation is 10.

Gaussian Distribution:

 

   


Where,
is the mean
is the standard deviation

>>
%% Gaussian vector with varying standard deviation
x = linspace(-15,15,257);
x = x(1:256);
a = (linspace(.1,10,10)).^2;
d=2*pi.*a;
for i=1:10,
fx(i,:) = (1/sqrt(d(i))).*exp(-((x.^2)./(2*a(i))));
figure(i);
subplot(2,1,1);
plot(real(fx(i,:)));
xlabel('x');
ylabel('f(x)');
title('Gaussian function');

Ffx(i,:) = fft(fx(i,:));
Ffx2(i,:) = fftshift(abs(Ffx(i,:)));
delx = x(2)-x(1);
xi = linspace(-1/(2*delx),1/(2*delx),257);
xi = xi(1:256);
figure(i)
subplot(2,1,2);
plot(xi,(real(Ffx2(i,:))));
xlabel('Frequency (1/\deltax)');
ylabel('real (Fourier f(x))');
title('FFT of Gaussian function');
end

Answer: As the function gets broader in x-domain (standard deviation increases),


the Fourier transform of the function gets narrower in the frequency domain

8
Priyanka Jillella

= 0.1 = 1.2

= 2.3 = 3.4

= 4.5 = 5.6

9
Priyanka Jillella

= 6.7 = 7.8

= 8.9 = 10.0

10
Priyanka Jillella

5. Demonstrate the effects of aliasing using a 1D DFT. I would suggest taking the DFT of a cos function for higher
and higher frequencies. Demonstrate the folding over of high frequencies to low frequencies in both the
spatial and Fourier domains.

Aliasing:

>>T=1/700;
n=0:699;
ft=cos(2*pi*800*n*T)+cos(2*pi*600*n*T)+cos(2*pi*100*n*T); % f1=800, f2=600, f3=100
Fft=fftshift(abs(fft(ft,700)));
f=linspace(-1,1-1/700,700)/(2*T);
figure(2);
plot(f,real(Fft),'k');
xlabel('frequency Hz');
ylabel('real (Fourier f(t))');
title('FFT cos(2\pi\omegat)');

Answer: In the above graph we see


that the fourier transform of the
function f(t) which has
frequencies: 800Hz, 600Hz, 100Hz
results in a frequency spectrum
that is centered at 100Hz. This is
resulted due to aliasing.

Folding:

%% Aliasing with Folding


T=1/700;
n=0:699;
ft=cos(2*pi*500*n*T);
Fft=fftshift(abs(fft(ft,700)));
f=linspace(-1,1-1/700,700)/(2*T);
figure(2);
plot(f,real(Fft),'b');
xlabel('frequency Hz');
ylabel('real (Fourier f(t))');
title('FFT cos(2\pi\omegat)');

We saw in aliasing that any frequency greater than the sampling frequency
shows up as a lower frequency. Folding is another way of looking at aliasing
phenomenon, where the observed frequency of a sampled signal differs from
the actually frequency, even though it is less than the sampling frequency
but greater than half the sampling frequency.

11
Priyanka Jillella

6. Perform an experiment measuring the speed of the DFT and report on your results. You should use
the tic and toc Matlab commands to measure the speed of the FFT function in Matlab. Perform an
FFT of a non-zero vector of sizes 4,8,32,and 256 and measure the speed of the FFT function. (Hint: it
will be more accurate to perform 1000 FFTs and then divide the resulting time by 1000 than perform a
single FFT and measure the time.) Now, repeat the same experiment using vectors of size 3,7,31, and
255 and report your results. Comment on your results. (Hint: its ok if your results dont make sense to
you!).

>> n=input('size of the vector: ');


a=rand(1,n);
minTime = Inf;
tstart = tic;
for i=1:1000,
A=fft(ae);
telapsed = toc(tstart);
minTime = min(telapsed,minTime);
end
averageTime = toc/1000

size of the vector: 4 size of the vector: 32

averageTime = averageTime =

0.0828 0.2382

size of the vector: 8 size of the vector: 256

averageTime = averageTime =

0.1862 0.2610

size of the vector: 3 size of the vector: 31

averageTime = averageTime =

0.4022 0.4355

size of the vector: 7 size of the vector: 255

averageTime = averageTime =

0.4223 0.4614

Answer: From the results it can be inferred that the time taken to evaluate
FFT of a vector with even number of samples is less than that for a vector
with odd number of samples.

12

Das könnte Ihnen auch gefallen