20011P0417 DSP Matlab Assignment
20011P0417 DSP Matlab Assignment
ASSIGNMENT
By Nuthi Keerthi Priya
Roll no:20011p0417
WEEK 5 EXPERIMENT-1
Numerically verify the validity of the shift property as follows: (i) create a vector of length 11
with random entries using the rand function; (ii) compute its DTFT at 501 equispaced points
over the interval [0, π]; (iii) evaluate numerically e −j2ωX(e jω) over the same set of points; (iv)
form a shifted sequence by adding two zeros at the beginning of the vector created in (i); (v)
compute the shifted vector’s DTFT at 501 equispaced points over the interval [0, π]; (vi) finally
compute the maximum absolute error of the difference vector and confirm that the value is
extremely small.
PROGRAM:
clc;
clear all
close all
%1
x=rand(1,11);
%2
N=501;
w=0:pi/500:pi;
[h,w]=freqz(x,1,N);
subplot(211);
plot(w/pi,abs(h));
title('original');
xlabel('frequency')
ylabel('magnitude')
%3numerical calculation;
d = exp(-1j*2*w) .* h;
%4
shifted_X = [0,0 x];
%5
[h2,w] = freqz(shifted_X, 1, N);
subplot(212);
plot(w/pi,abs(h2));
title('original');
xlabel('frequency')
ylabel('magnitude')
%6
e=max(abs(h-h2));
emin=min(abs(h-h2));
disp(e);
disp(emin);
OUTPUT:
WEEK 5 EXPERIMENT-2
Consider the LTI system specified by the difference equation y[n] = 0.8 y[n −1]
+ x[n]. Let the input to this system be x[n] = cos(0.05πn) u[n]. (a) Generate 100
samples of the input x[n] and store it in the vector x. (b) Understand MATLAB’s
filter command and obtain the output y using y = filter(b,a,x); (the vectors b
and a contain the numerator and denominator coefficients of the rational
transfer function H(e jω)). (c) Plot x and y in a figure one below the other (use
the command subplot). Observe the initial cycles and compare them with the
later ones; what are the main differences? Can you explain why the initial part
is different? (d) Measure the peak amplitude of the output and the delay
between the input and the output in the steady-state portion. Compare the
measured delay with the theoretical values (assume the input to be
cos(0.05πn) for the theoretical computation.
PROGRAM:
OUTPUT:
clc;
clear all;
close all;
%a
n = 0:99;
x = cos(0.05*pi*n) .* (n >= 0); % Generating the input signal x[n]
%b
b = 1;
a = [1, -0.8];
y = filter(b, a, x);
%c
subplot(2, 1, 1);
stem(n, x);
xlabel('n');
ylabel('x[n]');
title('Input Signal');
subplot(2, 1, 2);
stem(n, y);
xlabel('n');
ylabel('y[n]');
title('Output Signal');
OUTPUT:
WEEK 8 EXPERIMENT-1
1.Consider the notch filter H(z) = 1 − 2 cos θ z −1 + z −2 1 − 2r cos θ
z−1 + r 2 z−2 Let θ = π/3. Plot the magnitude frequency response for
r = 0.9, r = 0.95, r = 0.99, and r = 0.999.
PROGRAM:
clc;
clear;
close all;
T=pi/3;
r=0.9;
w=-1*pi:0.01:pi;
a=[1 -2*cos(T) 1];
b=[1 -2*r*cos(T) r*r];
H=freqz(a,b,w);
subplot(311);
plot(abs(H),'DisplayName','r=0.9');
hold on
subplot(312);
plot(angle(H),'DisplayName','r=0.9');
hold on
subplot(313);
t=zplane(a,b);
hold on;
r1=0.95;
a1=[1 -2*cos(T) 1];
b1=[1 -2*r1*cos(T) r1*r1];
H1=freqz(a1,b1,w);
subplot(311);
plot(w,abs(H1),'DisplayName','r=0.95');
legend;
subplot(312);
plot(angle(H1),'DisplayName','r=0.95');
legend;
subplot(313);
t1=zplane(a,b)
r2=0.99;
a2=[1 -2*cos(T) 1];
b2=[1 -2*r2*cos(T) r2*r2];
H2=freqz(a2,b2,w);
subplot(311);
plot(abs(H2),'DisplayName','r=0.99');
legend;
subplot(312);
plot(angle(H2),'DisplayName','r=0.99');
legend;
subplot(313);
t2=zplane(a,b);
r3=0.999;
a3=[1 -2*cos(T) 1];
b3=[1 -2*r3*cos(T) r3*r3];
H3=freqz(a3,b3,w);
subplot(311);
plot(abs(H3),'DisplayName','r=0.999');
legend;
subplot(312);
plot(angle(H3),'DisplayName','r=0.999');
legend;
subplot(313);
t3=zplane(a,b);
legend([t,t1,t2,t3],{'0.9','0.95','0.99','0.999'});
OUPUT:
WEEK 8 EXPERIMENT-2
PROGRAM:
clc;
clear;
close all;
T=pi/10;
r=0.8;
dw=2*pi/1000;
w=-1*pi:dw:pi;
a=[1 0 -1];
b=[1 -2*r*cos(T) r*r];
H=freqz(a,b,w);
subplot(311);
plot(w,abs(H));
subplot(312);
plot(angle(H));
subplot(313);
zplane(a,b);
OUTPUT:
WEEK 9 EXPERIMENT-2
Compute and plot the phase response of H(z) = [(1 +z-1)/2]6. (a) Determine analytically
∠H(ejw) and using this expression plot the
phase response. (b) Use MATLAB’s freqz command and obtain the phase response
and compare it with the results obtained from the previous plot.
PROGRAM:
clc;
clear all;
close all;
%analytical calculation
w = linspace(0, 2*pi);%w ranging from 0 to 2*pi
H = (1/64) * (1 + 6*exp(-1i*w) + 15*exp(-2i*w) + 20*exp(-3i*w) + 15*exp(-4i*w) +
6*exp(-5i*w) + exp(-6i*w));
phase = angle(H);
subplot(2,1,1);
plot(w, phase);
xlabel('Frequency (\omega)');
ylabel('Phase Response');
title('Phase Response - Analytical Calculation');
%using matlab command
b = [1/64, 6/64, 15/64, 20/64, 15/64, 6/64, 1/64];
a=1;
w=0:0.1:2*pi
[h,w]=freqz(b, a,w);
ph = angle(h);
subplot(2,1,2);
plot(w, ph);
xlabel('Frequency (\omega)');
ylabel('Phase Response');
title('Phase Response - freqz Command');
OUTPUT:
WEEK 9 EXPERIMENT-3
Compute and plot the phase response using the functions freqz, angle, phasez, unwrap, and
phasedelay for the following systems: (a) The pure delay system given by y[n] = x[n − 15]
PROGRAM:
clc;
clear all;
close all;
%a
b=1;
a=1;
[h,w]=freqz(b,a,1024);
subplot(2,1,1);
plot(w, unwrap(angle(h)));
xlabel('Frequency (\omega)');
ylabel('Phase Response');
title('Phase Response-Pure Delay System');
%b
b = [1 1.655 1.655 1];
a = [1 -1.57 1.264 -0.4];
[h, w] = phasez(b, a, 1024);
subplot(2,1,2);
plot(w, unwrap(h));
xlabel('Frequency (\omega)');
ylabel('Phase Response');
title('Phase Response-System H(z)');
OUTPUT:
WEEK 9 EXPERIMENT-4
PROGRAM:
clc;
clear all;
close all;
b = [1 1 1 1];
a = [1 0.9 0.81 0.927];
gd = grpdelay(b,a);
plot(gd);
xlabel('Frequency (\omega)');
ylabel('Group Delay');
title('Group Delay of the System');
OUTPUT: