Anda di halaman 1dari 13

# Lab # 6

FOURIER TRANSFORM
Example1: Type-in the following matlab program, save it with the file
name lab61.m and execute it.
Programe#01
T=0.0005;
tau=10;
t=-tau:T:tau;
f=-12:0.1:12;
x=(t>=0).*exp(-t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=5
T=0.0005;
tau=5;
t=-tau:T:tau;
f=-12:0.1:12;
x=(t>=0).*exp(-t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=2
T=0.0005;
tau=2;
t=-tau:T:tau;
f=-12:0.1:12;
x=(t>=0).*exp(-t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=1
T=0.0005;
tau=1;
t=-tau:T:tau;
f=-12:0.1:12;
x=(t>=0).*exp(-t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

The Fourier transform of the above signal, i.e. x(t)=e -t u(t), is given by:

X(f )

1
1 j 2f

Plot ADS and PS of X(f) and compare it with the results obtained with the dtft
function

Programe#02
t=-10:0.0005:10;
f=-12:0.1:12;
x=1./(1+j*2*pi*f);
subplot(3,1,1);
plot(f,x);
grid on;
axis([min(t) max(t) min(x)-.1
max(x)+.1]);
xlabel('time(second)');
ylabel('x(t)')
xamp=abs(x);
subplot(3,1,2);
plot(f,xamp);
grid on;
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1]);
ylabel('X(f)');
xlabel('frequency');
xph=angle(x);
subplot(3,1,3);
plot(f,xph);
grid on;
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1]);
xlabel('frequency');
ylabel('<X(f)');

Graph#02

## Example 2: Modify program of example 1 by replacing line 5 of the

program by fo=1; x=cos(2*pi*fo*t); Now change the value of tau to 3, 2, 1,
0.75, 0.5, and 0.25.

Program#02
T=0.0005;
tau=10;
t=-tau:T:tau;
f=-12:0.1:12;
fo=1; x=cos(2*pi*fo*t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311),plot(t,x),
grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph),
grid on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=3
T=0.0005;
tau=3;
t=-tau:T:tau;
f=-12:0.1:12;
fo=1; x=cos(2*pi*fo*t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x),grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph),
grid on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])

xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=0.75
T=0.0005;
tau=0.75;
t=-tau:T:tau;
f=-12:0.1:12;
fo=1; x=cos(2*pi*fo*t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid
on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph),
grid on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=0.25

T=0.0005;
tau=0.25;
t=-tau:T:tau;
f=-12:0.1:12;
fo=1; x=cos(2*pi*fo*t);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid
on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph),
grid on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

## Example 3: Modify program of example 1 by replacing line 5 of the

program by x=ones(1,length(t)); Now change the value of tau to 3, 2, 1, 0.75, 0.5,
and 0.25.

Programe#03

T=0.0005;
tau=10;
t=-tau:T:tau;
f=-12:0.1:12;
x=ones(1,length(t));
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=3
T=0.0005;
tau=3;
t=-tau:T:tau;
f=-12:0.1:12;
x=ones(1,length(t));
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=0.75

T=0.0005;
tau=0.75;
t=-tau:T:tau;
f=-12:0.1:12;
x=ones(1,length(t));
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1 max(x)
+.1])
xlabel('time (seconds)'), ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'), ylabel('<X(f)')

At tau=0.25
T=0.0005;
tau=0.25;
t=-tau:T:tau;
f=-12:0.1:12;
x=ones(1,length(t));
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1 max(x)
+.1])
xlabel('time (seconds)'), ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'), ylabel('<X(f)')

program by

## tp=1; ON=0.5; x=rektwave(t,tp,ON).Now change the value of tau to 4, 3, 2, 1.5, and

1,

Programe#04
T=0.0005;
tau=10;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; ON=0.5;
x=rektwave(t,tp,ON);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid
on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=4
T=0.0005;
tau=4;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; ON=0.5;
x=rektwave(t,tp,ON);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid
on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=2

T=0.0005;
tau=2;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; ON=0.5;
x=rektwave(t,tp,ON);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid
on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=1
T=0.0005;
tau=1;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; ON=0.5;
x=rektwave(t,tp,ON);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid
on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

## Example 5: Modify the program of example 1 by replacing line 5 of the

program tp=1; x=triwave(t,tp); Now change the value of tau to 4, 3, 2, 1.5, and
1,

Programe#05
T=0.0005;
tau=10;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=triwave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid
on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=4
T=0.0005;
tau=4;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=triwave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid
on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
title('09TL63')
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=2

T=0.0005;
tau=2;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=triwave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid
on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=1
T=0.0005;
tau=1;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=triwave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid
on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp),
grid on
axis([min(f) max(f)
min(Xamp)-.1 max(Xamp)
+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid
on
axis([min(f) max(f)
min(Xph)-.1 max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

## program by tp=1; x=sawave(t,tp); Now change the value of tau to 4, 3, 2,

1.5, and 1,

Programe#06
T=0.0005;
tau=10;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=sawave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x),
grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=4
T=0.0005;
tau=4;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=sawave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x),
grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=2
T=0.0005;
tau=2;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=sawave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')

At tau=1

T=0.0005;
tau=1;
t=-tau:T:tau;
f=-12:0.1:12;
tp=1; x=sawave(t,tp);
[X Xamp Xph]=dtft(x,t,f);
subplot(311), plot(t,x), grid on
axis([min(t) max(t) min(x)-.1
max(x)+.1])
xlabel('time (seconds)'),
ylabel('x(t)')
subplot(312), plot(f,Xamp), grid on
axis([min(f) max(f) min(Xamp)-.1
max(Xamp)+.1])
ylabel('|X(f)|')
subplot(313), plot(f,Xph), grid on
axis([min(f) max(f) min(Xph)-.1
max(Xph)+.1])
xlabel('frequency (Hz)'),
ylabel('<X(f)')