You are on page 1of 20

DSP LAB REPORT

Abhinav Malhotra
03/EC/07

03/EC/07

EXPERIMENT NO: 1
An LTI system is specified by the equation, y[n]=0.9y[n-1]+x[n]
(a) Find H(z) and show the pole-zero plot
(b) Plot |H(exp(jw)| and phase(H(exp(jw))
(c) Calculate and plot the steady state response to x[n]=cos(0.05n)u[n]

THEORY
We calculated response as:

MATLAB CODE:

clc;
clear all;

% to plot zeros and poles of Hz

zplane(zero(Hz),pole(Hz))

% to plot the magnitude and phase of tf

03/EC/07
freqz([1],[1 -0.9]);

% to plot the magnitude and phase of tf

freqz([1 cos(.05*pi)],[1 -2.9 (18*cos(.05*pi)+1) -0.9]);

OUTPUTS:

Pole-zero plot

03/EC/07

03/EC/07

Magnitude and phase response of output for given input.

03/EC/07

EXPERIMENT NO: 2
Let x[n] be a 4-point sequence:
x[n]= 1 ; 0<=n<=3
= 0 ; otherwise
(a) Compute DTFT and plot its magnitude and phase
(b) Compute 4-point, 8-point and 16-point DFT of x[n]

THEORY
The DFT of a sequence of length N is given as

Zero-padding can be done to the sequence to calculate P point DFT.

The discrete Fourier transform computes the values of the z transform for evenly spaced points around the
unit circle for a given sequence.
If the sequence to be represented is of finite duration, i.e., has only a finite number of non-zero values, the
transform is discrete Fourier transform.
N-1
kn/N

n=0

k = 0,1,2..,N-1
x(n) = {1,1,1,1}
4-point DFT
N=4
N-1
kn/N

n=0

k = 0,1,2..,N-1
3
kn/4

n=0

k = 0,1,2,3

03/EC/07
k/4

+x(2) e-j2

2/4

+e-j2

X(k) = x(0)+x(1) e-j2

k2/4

k3/4

+x(3) e-j2

X(0) = 1+1+1+1=4
/4

X(1) = 1+ e-j2

+e-j2

3/4

=0
2 /4

+e-j2

3 /4

+e-j2

X(2) = 1+ e-j2

4/4

+e-j2

6/4

6/4

+e-j2

=0
X(3) = 1+ e-j2

9/4

=0
8-point DFT
N=8
X(n) = {1,1,1,1,0,0,0,0}
N-1
kn/N

n=0

k = 0,1,2..,N-1
7
kn/8

X(k) = x(n) e-j2

n=0

k = 0,1,2,3,4,5,6,7
X(k) = x(0)+x(1) e

-j2 k/8

k5/8

+x(5) e-j2

k2/8

+x(2) e-j2
k6/8

+x(6) e-j2

k/8

k4/8

+x(4) e-j2

k7/8

+x(7) e-j2

k2/8

X(k) = 1+x(1) e-j2

k3/8

+x(3) e-j2

+x(2) e-j2

k3/8

+x(3) e-j2

X(0) = 1+1+1+1 = 4
/8

X(1) = 1+ e-j2

2/8

+e-j2

3/8

+e-j2

= 1-2.414j
2 /4

+e-j2

3 /8

+e-j2

X(2) = 1+ e-j2

4/4

+e-j2

6/4

6/8

+e-j2

8 /8

+e-j2

=0
X(3) = 1+ e-j2

9/8

= 1-0.414j
4 /8

+e-j2

5 /8

+e-j2

X(4) = 1+ e-j2

12/8

=0
X(5) = 1+ e-j2

10/8

15/8

+e-j2

= 1+0.414j
6/8

X(6) = 1+ e-j2

12/8

+e-j2

18/8

+e-j2

03/EC/07
=0
7/8

X(7) = 1+ e-j2

14/8

+e-j2

21/8

+e-j2

= 1+2.414j
16point DFT
N = 16
X(n) = {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0}
N-1
kn/N

n=0

k = 0,1,2..,N-1
15
kn/16

X(k) = x(n) e-j2

n=0

k = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
-j2 k/16

X(k) = 1+x(1) e

-j2 k2/16

k3/16

+(3) e-j2

+x(2) e

X(0) = 1+1+1+1 = 4
/16

X(1) = 1+ e-j2

2/16

+e-j2

3/16

+e-j2

= 3.007-2.007j
2 /16

4/16

6/16

6/16

9/16

4 /16

8 /16

12/16

5 /16

10/16

+e-j2

12/16

+e-j2

14/16

+e-j2

X(2) = 1+ e-j2

+e-j2

+e-j2

= 1-2.414j
3 /16

X(3) = 1+ e-j2

+e-j2

+e-j2

= 1.593-1.247j
X(4) = 1+ e-j2

+e-j2

+e-j2

=0
X(5) = 1+ e-j2

+e-j2

15/16

= 0.833+0.167j
6/16

+e-j2

7/16

+e-j2

X(6) = 1+ e-j2

18/16

=0
X(7) = 1+ e-j2

21/16

= 1.166-2.012j
8 /16

16 /16

24 /16

9 /16

18 /16

27/16

X(8) = 1+ e-j2

+e-j2

+e-j2

=0
X(9) = 1+ e-j2

+e-j2

+e-j2

= 0.407+0.593j
10 /16

X(10) = 1+ e-j2

20/16

+e-j2

30/16

+e-j2

= 1+0.414j

03/EC/07

11 /16

22/16

+e-j2

12 /16

24/16

+e-j2

13 /16

26/16

+e-j2

14 /16

28/16

+e-j2

15 /16

30/16

+e-j2

X(11) = 1+ e-j2

+e-j2

33/16

= 0.833-0.167j
X(12) = 1+ e-j2

+e-j2

36/16

=0
X(13) = 1+ e-j2

+e-j2

39/16

= -0.247+1.247j
X(14) = 1+ e-j2

+e-j2

42/16

= 1+j
X(15) = 1+ e-j2

+e-j2

45/16

= 3.007+2.007j
MATLAB CODE:
clc
clear all
close all
N1=4;
N2=8;
N3=16;

x1=zeros(1,N1);
x1(1:4)=1;
x2=zeros(1,N2);
x2(1:4)=1;
x3=zeros(1,N3);
x3(1:4)=1;

Xk1=zeros(1,N1);
Xk2=zeros(1,N2);
Xk3=zeros(1,N3);

03/EC/07
for k=1:N1
for n=1:N1
Xk1(k)=Xk1(k)+x1(n)*exp(-j*2*pi*k*n/N1);
end
end

for k=1:N2
for n=1:N2
Xk2(k)=Xk2(k)+x2(n)*exp(-j*2*pi*k*n/N2);
end
end

for k=1:N3
for n=1:N3
Xk3(k)=Xk3(k)+x3(n)*exp(-j*2*pi*k*n/N3);
end
end

w1=0:2*pi/100:2*pi*99/100;

% subplot(2,1,1); plot(w1, abs(fft(x1,100))); xlabel('w(rad/s)'); ylabel('magnitude of DTFT');

%
% subplot(2,1,2); plot(w1, angle(fft(x1,100))); xlabel('w(rad/s)'); ylabel('phase of DTFT');

subplot(3,1,1); stem(abs(Xk1)); ylabel('4-point DFT');

subplot(3,1,2); stem(abs(Xk2)); ylabel('8-point DFT');
subplot(3,1,3); stem(abs(Xk3)); ylabel('16-point DFT');

10

03/EC/07

OUTPUT

11

03/EC/07

EXPERIMENT NO:3
For given sequence:
x[n]=cos(0.48n) + cos(0.52n) ;
(a) Plot the 100 point DFT for 0<=n<=10 (Pad 90 zeroes)
(b) Plot the 100-point DFT of x[n].
MATLAB CODE:
%DFT
N=100;
n=1:100;
x1=zeros(1,N);
x2=zeros(1,N);
x(n)=(cos(.48*pi*n)+cos(.52*pi*n));
x1(1:10)=x(1:10);
x2=x;
fftx1=fft(x1,100);
fftx2=fft(x2,100);
w=0:2*pi/100:2*pi*99/100;

12

03/EC/07

OUTPUT:

13

03/EC/07

EXPERIMENT NO: 4
Design a length-21 differentiator using a Hamming window
MATLAB CODE:
clc
clear all
close all

hd=zeros(1,21);
w=hamming(21)
a=0.54
for n=1:21
hd(n)=(j/pi)*(((pi*sin(pi*(n-a)))/(n-a))+(cos(pi*(n-a))/(n-a)^2))
end
h=(w').*(hd);

w1=0:2*pi/100:2*pi*99/100;

subplot(2,2,3);plot(w1,abs((fft(h,100)))); xlabel('w(rad/s)'); ylabel('magnitude of differentiator after

windowing');

14

03/EC/07

OUTPUT:

15

03/EC/07

EXPERIMENT NO: 5
To design a length-25 digital hilbert transformer using a hanning window

MATLAB CODE:
clc
clear all
close all

h=zeros(1,25);
w=hanning(25);
a=0.5;

for n=1:25
hd(n)=(1-cos(pi*(n-a)))/(pi*(n-a))
end

w1=0:2*pi/100:2*pi*99/100;

h=(w').*(hd);
subplot(2,2,1);plot(w1,abs((fft(hd,100)))); xlabel('w(rad/s)'); ylabel('magnitude response of the hilbert
transformer (orginally)');

subplot(2,2,3);plot(w1,abs((fft(h,100)))); xlabel('w(rad/s)'); ylabel('magnitude response of hilbert

transformer(after windowing)');

16

03/EC/07
subplot(2,2,4);plot(w1,angle((fft(h,100)))); xlabel('w(rad/s)'); ylabel('phase response of the hilbert
transformer');

OUTPUT:

Before

Windo
wing

After
Windo
wing

17

03/EC/07

EXPERIMENT NO:6
To see the effect of up-sampling and down-sampling on a signal
(a) Up-sample a sequence given by x[n] = sin(0.24n) 0<=n<=49; by factor L=3.
(b) Down-sample the sequence given by x[n] = sin(0.24n) 0<=n<=149; by a factor of M=3.

MATLAB CODE:
clc
clear all
close all
n=1:50;
x=ones(1,50);
for n=1:50
x(n)=sin(0.24*pi*n);
end;

%upsampling
L=3;
y=zeros(1,150);

y(1)=x(1);
for i=1:49
y(3*i+1)=x(i+1);
end;
subplot(3,2,1);stem(x);
subplot(3,2,3);stem(y);

%downsampling
M=3;
18

03/EC/07
z(1)=x(1);
for i=1:16
z(i+1)=x(3*i+1);
end;
subplot(3,2,5);stem(z);

a=abs(fftshift(fft(x)));
b=abs(fftshift(fft(y)));
c=abs(fftshift(fft(z)));

subplot(3,2,2);stem(a);
subplot(3,2,4);stem(b);
subplot(3,2,6);stem(c);

OUTPUT:

19

03/EC/07

25
20

0. 5

15
0
10
-0.5
-1

5
10

20

30

40

50

10

20

30

40

50

30

0. 5

20

0
10
-0.5
-1

50

100

150

50

100

150

10
8

0. 5

6
0
4
-0.5
-1

2
5

10

15

20

10

15

20

20