Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

In Lab Excersice

Q1 . Determine the time signals represented by following dtfs coefficient.


ak=1+cos(5k/9)+jsin(7k/27)
program
k=0:53;
ak=1+cos(5*pi*k/9)+j*sin(7*pi*k/27);
N=54;
for i=0:N-1
xn=0;
for k=0:N-1
xn(k+1)=ak(k+1).* exp(2*j.*(pi./N).*k.*i);
end
x(i+1)=sum(xn);
end
subplot(2,1,1)
stem(0:53,x./N)
subplot(2,1,2)
stem(0:53,ifft(ak))
1.5
1
0.5
0
-0.5

10

20

30

40

50

60

10

20

30

40

50

60

1.5
1
0.5
0
-0.5

Q2. Calculate DTFT and DFT of signal, x[n]. Plot magnitude and phase spectra. Verify
your answer.
x[n]=(1/3)^|n|.u(-n-2)

Program
%dtft
n=-20:20;
w=-pi:0.1:pi;
u=@(n)(1.*(n>=0));
x=((1/3).^abs(n).*u(-n-2));
for m=1:length(w)
s=0;
for l=1:length(n)
X(l)=x(l).*exp((-1j).*w(m).*n(l));
s=s+sum(X);
end
s1(m)=s;
end
subplot(3,1,1)
stem(1:length(w),(s1))
s2=abs(s1);
subplot(3,1,2)
stem(s2)
s3=angle(s1);
subplot(3,1,3)
stem(s3)
10
5
0
-5

10

20

30

40

50

60

70

10

20

30

40

50

60

70

10

20

30

40

50

60

70

10
5
0
5
0
-5

%DFT
n=-20:20;
N=8;
u=@(n)(1.*(n>=0));
x=((1/3).^abs(n).*u(-n-2));
for m=1:length(w)

s=0;
for l=1:length(n)
X(l)=x(l).*exp((-1*2*pi*j).*m./N.*n(l));
s=s+sum(X);
end
s1(m)=s;
end
subplot(3,1,1)
stem(1:length(w),(s1))
s2=abs(s1);
subplot(3,1,2)
stem(s2)
s3=angle(s1);
subplot(3,1,3)
stem(s3)

5
0
-5

10

20

30

40

50

60

70

10

20

30

40

50

60

70

10

20

30

40

50

60

70

6
4
2
0
5
0
-5

Post lab
Q1.Use the defining equation for the DTFS coefficients to evaluate the FS
representation of discrete time signal.
x[n] =1+cos(3n /12)+sin(2n / 36)
Sketch the magnitude and phase spectra. Verify answer using fft.
n=0:71;
x=(1+cos(3.*pi.*n./12)+sin(2.*pi.*n./36));
N=72;
for i=0:N-1
xn=0;
for k=0:N-1
xn(k+1)=(x(k+1).*exp(-2.*pi.*1j./N.*k.*i));
end
ak(i+1)=sum(xn);

end
subplot(4,1,1)
stem(0:71,ak)
subplot(4,1,2)
stem(0:71,fft(x))
y=abs(ak);
z=angle(ak);
subplot(4,1,3)
stem(y)
subplot(4,1,4)
stem(z)
100
0
-100
100

10

20

30

40

50

60

70

80

10

20

30

40

50

60

70

80

10

20

30

40

50

60

70

80

10

20

30

40

50

60

70

80

0
-100
100
50
0
5
0
-5

2. Determine DTFT and DFT of signal, x[n] = ((1/3) n cos (3n)) u [n + 2].
n=-20:20;
x=(1/3).^n.*cos(3.*n).*1.*(n+2>=0);
w=-pi:0.1:pi;
for m=1:length(w)
s=0;
for l=1:length(n)
X(l)=x(l).*exp((-1j).*w(m).*n(l));
s=s+sum(X);
end
s1(m)=s;
end
subplot(3,1,1)
stem(1:length(w),(s1))
s2=abs(s1);
subplot(3,1,2)
stem(s2)
s3=angle(s1);
subplot(3,1,3)

stem(s3)
1000
500
0
-500

10

20

30

40

50

60

70

10

20

30

40

50

60

70

10

20

30

40

50

60

70

600
400
200
0
5
0
-5

n=-20:20;
N=8;
x=(1/3).^n.*cos(3.*n).*1.*(n+2>=0);
for m=1:length(w)
s=0;
for l=1:length(n)
X(l)=x(l).*exp((-1*2*pi*j).*m./N.*n(l));
s=s+sum(X);
end
s1(m)=s;
end
subplot(3,1,1)
stem(1:length(w),(s1))
s2=abs(s1);
subplot(3,1,2)
stem(s2)
s3=angle(s1);
subplot(3,1,3)
stem(s3)

500
0
-500

10

20

30

40

50

60

70

10

20

30

40

50

60

70

10

20

30

40

50

60

70

600
400
200
0
5
0
-5

You might also like