DSP Report
DSP Report
DSP Report
TECHNOLOGY
Name of the Experiment: Z-transform and Its Application and Frequency domain
analysis of DT signal and systems
Date of Performance: __/01/2024
Date of Submission: 03/03/2024
Submitted by:
Level: 3 Term: 1
Department: EEE
Section: C1
Question 1
Code
%% C4
a=[1 -1/2];
b=[1 1/3];
n=0:10;
x1=(n==0);
y1=filter(b,a,x1);
figure(4)
stem(n,y1),title("Impulse Response");
figure(5)
zplane(b,a);
output:
Input Code: C5
clc;
clear;
close all;
b=[3 -4];
a=[1 -3.5 1.5];
figure(1)
zplane(b,a)
[r p c]=residuez(b,a)
Outputs:
For the given system function, poles were found to be and 3. ROC and h[n]for
different condition are shown.
Causal condition:
clc;
clear;
close all;
b=[2 16 44 56 32];
a=[3 3 -15 18 -12];
zplane(b,a)
[r p c]=residuez(b,a)
Outputs:
r=
-0.0177 + 0.0000i
9.4914 + 0.0000i
-3.0702 + 2.3398i
-3.0702 - 2.3398i
p=
-3.2361 + 0.0000i
1.2361 + 0.0000i
0.5000 + 0.8660i
0.5000 - 0.8660i
c=
-2.6667
the factored form the system function is
clc;
clear;
close all;
clc;
clear;
close all;
b=[1];
a=[1 -2.5 1];
[r p c]=residuez(b,a)
Outputs:
r=
1.3333
-0.3333
p=
2.0000
0.5000
c=
[]
Observations:
We can see that the system has two poles in |𝑧| = 2 and |𝑧| = 0.5
So, for the system being causal and stable, it must have no poles in the region |𝑧| > 1.
We can achieve that by cascading a system with H1 = 1 – 2z-1
For the system being anti-causal and stable, it must have no poles in the region |𝑧| < 1.
We can also achieve this by cascading a system with H2 = 1 – 0.5z-1
Making the system stable while it is
(a) causal (b) anti-causal
clc
clear
clear all
b = [1];
a = [1 -2.5 1];
n1 = conv(b, [1 -2]);
n2 = conv(b, [1 -0.5]);
subplot(3,2,1),zplane(b,a),title("The Main System");
subplot(3,2,2),stem(impz(b,a)),title("Impulse Response for The Main System");
subplot(3,2,3),zplane(n1,a),title('System with Causal Stability');
subplot(3,2,4),stem(impz(n1,a)),title("Impulse Response for System with Causal
Stability");
subplot(3,2,5),zplane(n2,a),title("System with Anti-Causal Stability");
subplot(3,2,6),stem(impz(n2,a)),title("Impulse Response for System with AntiCausal
Stability");
Question 2:
Generalized code for schur cohn stability test:
function isStable = schurCohnStabilityTest(coefficients)
% Input:
% coefficients: Coefficients of the characteristic polynomial in descending
order (highest degree to lowest)
result :
>>
Question : 3
Problem 2.1
Code :
%% Problem for Example 2
clc
clear
close all
%% GENERATING A SINC PULSE
f_c = 1/8; %DEFINING FREQUENCY VARIABLE FOR SINC PULSE
n = -131:131; %DEFINING THE INDEX FOR SINC PULSE
x = sinc(2*f_c*n);
%END OF SINC PULSE
figure(1);stem(n, x, '.k');
xlabel('n'),ylabel('x(n)'),title('Discrete time signal');
M = 101; %NUMBER OF POINTS IN DIGITAL FREQUENCY GRID
w = linspace(-0,2*pi,M); %DEFINING THE DIGITAL FREQUENCY GRID
dw = w(2) - w(1);%RESOLUTION OF DIGITAL FREQUENCY
X = zeros(1,M);%INITIALIZING THE DTFT OF x(n)
for i1 = 1:M
for i2 = 1:length(x)
X(i1) = X(i1) + x(i2)*exp(-i*w(i1)*n(i2));
end
end
figure(2), plot(w,abs(X), 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)'), ylabel('X(w)');
title('FREQUENCY SPECTRA');
%RECONSTRUCTION OF SIGNAL
n_re = -131:131;
x_re = zeros(1,length(n_re)); %INITIALIZING RECONSTRUCTED SIGNAL
for i1 = 1:M
for i2 = 1:length(x_re);
x_re(i2) = x_re(i2) + 1/(2*pi)*X(i1)*exp(-i*w(i1)*n_re(i2))*dw;
end
end
figure(3), stem(n_re, x_re,'.k', 'linewidth',1);
xlabel('t'), ylabel('x_{reconstructed}');
title('Reconstructed signal');
output :
Example 2.2
Code :
%% Problem for Example 2
% problem 3
clc
clear
close all
%% GENERATING A SINC PULSE
f_c = 1/8; %DEFINING FREQUENCY VARIABLE FOR SINC PULSE
n = -131:131; %DEFINING THE INDEX FOR SINC PULSE
x = sinc(2*f_c*n);
%END OF SINC PULSE
figure(1);stem(n, x, '.k');
xlabel('n'),ylabel('x(n)'),title('Discrete time signal');
M = 101; %NUMBER OF POINTS IN DIGITAL FREQUENCY GRID
w = linspace(-2*pi,2*pi,M); %DEFINING THE DIGITAL FREQUENCY GRID
dw = w(2) - w(1);%RESOLUTION OF DIGITAL FREQUENCY
X = zeros(1,M);%INITIALIZING THE DTFT OF x(n)
for i1 = 1:M
for i2 = 1:length(x)
X(i1) = X(i1) + x(i2)*exp(-i*w(i1)*n(i2));
end
end
figure(2), plot(w,abs(X), 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)'), ylabel('X(w)');
title('FREQUENCY SPECTRA');
%RECONSTRUCTION OF SIGNAL
n_re = -131:131;
x_re = zeros(1,length(n_re)); %INITIALIZING RECONSTRUCTED SIGNAL
for i1 = 1:M
for i2 = 1:length(x_re);
x_re(i2) = x_re(i2) + 1/(2*pi)*X(i1)*exp(-i*w(i1)*n_re(i2))*dw;
end
end
figure(3), stem(n_re, x_re,'.k', 'linewidth',1);
xlabel('t'), ylabel('x_{reconstructed}');
title('Reconstructed signal');
output:
Example2.3:
Problem 03: Verify the effect of changing index (n) to -40:120, -40:80. In each case observe the
reconstructed signal.
Matlab Code:
%% Problem for Example 2
% problem 3
clc
clear
close all
%% GENERATING A SINC PULSE
f_c = 1/8; %DEFINING FREQUENCY VARIABLE FOR SINC PULSE
n = -40:120; %DEFINING THE INDEX FOR SINC PULSE
x = sinc(2*f_c*n);
%END OF SINC PULSE
figure(1);stem(n, x, '.k');
xlabel('n'),ylabel('x(n)'),title('Discrete time signal');
M = 101; %NUMBER OF POINTS IN DIGITAL FREQUENCY GRID
w = linspace(-2*pi,2*pi,M); %DEFINING THE DIGITAL FREQUENCY GRID
dw = w(2) - w(1);%RESOLUTION OF DIGITAL FREQUENCY
X = zeros(1,M);%INITIALIZING THE DTFT OF x(n)
for i1 = 1:M
for i2 = 1:length(x)
X(i1) = X(i1) + x(i2)*exp(-i*w(i1)*n(i2));
end
end
figure(2), plot(w,abs(X), 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)'), ylabel('X(w)');
title('FREQUENCY SPECTRA');
%RECONSTRUCTION OF SIGNAL
n_re = -40:40;
x_re = zeros(1,length(n_re)); %INITIALIZING RECONSTRUCTED SIGNAL
for i1 = 1:M
for i2 = 1:length(x_re);
x_re(i2) = x_re(i2) + 1/(2*pi)*X(i1)*exp(-i*w(i1)*n_re(i2))*dw;
end
end
figure(3), stem(n_re, x_re,'.k', 'linewidth',1);
xlabel('t'), ylabel('x_{reconstructed}');
title('Reconstructed signal');
output
Example 2.4
Code
%% Problem for Example 2
% problem 3
clc
clear
close all
%% GENERATING A SINC PULSE
f_c = 1/8; %DEFINING FREQUENCY VARIABLE FOR SINC PULSE
n = -131:131; %DEFINING THE INDEX FOR SINC PULSE
x = sinc(2*f_c*n);
%END OF SINC PULSE
figure(1);stem(n, x, '.k');
xlabel('n'),ylabel('x(n)'),title('Discrete time signal');
M = 101; %NUMBER OF POINTS IN DIGITAL FREQUENCY GRID
w = linspace(-2*pi,2*pi,M); %DEFINING THE DIGITAL FREQUENCY GRID
dw = w(2) - w(1);%RESOLUTION OF DIGITAL FREQUENCY
X = zeros(1,M);%INITIALIZING THE DTFT OF x(n)
for i1 = 1:M
for i2 = 1:length(x)
X(i1) = X(i1) + x(i2)*exp(-i*w(i1)*n(i2));
end
end
figure(2), plot(w,abs(X), 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)'), ylabel('X(w)');
title('FREQUENCY SPECTRA');
%RECONSTRUCTION OF SIGNAL
n_re = -240:240;
x_re = zeros(1,length(n_re)); %INITIALIZING RECONSTRUCTED SIGNAL
for i1 = 1:M
for i2 = 1:length(x_re);
x_re(i2) = x_re(i2) + 1/(2*pi)*X(i1)*exp(-i*w(i1)*n_re(i2))*dw;
end
end
figure(3), stem(n_re, x_re,'.k', 'linewidth',1);
xlabel('t'), ylabel('x_{reconstructed}');
title('Reconstructed signal');
output :
Here, again the number of points is taken more than it’s needed. We had built our code in this sense that
the period N is infinity, thus the signal is aperiodic. However, our code doesn’t know that and works as if
N is a finite value. Thus, values beyond N will result in periodic signal.
Example 2.5
Code:
%% Problem for Example 2
% problem 5
clc
clear
close all
%% Constructing the given signal
n=-0.02:0.0005:0.02;
x=zeros(1,length(n));
for i5=1:length(n)
if n(i5)<=0.005 && n(i5)>=-0.005
x(i5)=sin(2*pi*n(i5)/0.010);
end
end
figure(1)
subplot(211);plot(n, x, 'k', 'linewidth', 2)
xlabel('t'), ylabel('x(n)')
title('Continous time signal');
subplot(212);stem(n, x, '.k', 'linewidth', 2)
xlabel('n'), ylabel('x(n)')
title('Discrete time signal');
%% Fourier
M=101;
w=linspace(-pi,pi,M);
dw=w(2)-w(1);
X=zeros(1,M);
for i1=1:M
for i2=1:length(x)
X(i1)=X(i1)+x(i2)*exp(-1i*w(i1)*n(i2));
end
end
figure(2)
subplot(211),plot(w,abs(X), 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)');ylabel('|X(w)|')
title('Magnitude Spectrum');
subplot(212),plot(w,angle(X)*180/pi, 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)');ylabel('angle(X(w))')
title('Phase Spectrum');
figure(3)
plot(w,X, 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)');ylabel('X(w)')
title('X(w)');
output :
Problem 06:
Verify the duality property of DTFT with rectangular pulse and sinc function.
Code
clc
clear
close all
%% RECTANGULAR PULSE
n = -40:40; %DEFINING THE INDEX FOR RECTANGULAR PULSE
x = [zeros(1,20) ones(1,41) zeros(1,20)];
%END OF RECTANGULAR PULSE
figure(1);subplot(211); stem(n, x, '.k');
xlabel('n'),ylabel('x(n)'),title('Discrete time signal');grid on;
M = 1001; %NUMBER OF POINTS IN DIGITAL FREQUENCY GRID
w = linspace(-pi,pi,M); %DEFINING THE DIGITAL FREQUENCY GRID
dw = w(2) - w(1);%RESOLUTION OF DIGITAL FREQUENCY
X = zeros(1,M);%INITIALIZING THE DTFT OF x(n)
for i1 = 1:M
for i2 = 1:length(x)
X(i1) = X(i1) + x(i2)*exp(-i*w(i1)*n(i2));
end
end
subplot(212), plot(w,X, 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)'), ylabel('X(w)');
title('FREQUENCY SPECTRA');grid on;
output
Sinc pulse
Matlab Code:
clc
clear
close all
%% SINC PULSE
f_c = 1/8; %DEFINING FREQUENCY VARIABLE FOR SINC PULSE
n = -40:40; %DEFINING THE INDEX FOR SINC PULSE
x = sinc(2*f_c*n);
%END OF SINC PULSE
figure(2);
subplot(211);
stem(n, x, '.k');
xlabel('n');
ylabel('x(n)');
title('Discrete time signal');
M = 10001; %NUMBER OF POINTS IN DIGITAL FREQUENCY GRID
w = linspace(-pi,pi,M); %DEFINING THE DIGITAL FREQUENCY GRID
dw = w(2) - w(1);%RESOLUTION OF DIGITAL FREQUENCY
X = zeros(1,M);%INITIALIZING THE DTFT OF x(n)
for i1 = 1:M
for i2 = 1:length(x)
X(i1) = X(i1) + x(i2)*exp(-i*w(i1)*n(i2));
end
end
subplot(212);
plot(w,abs(X), 'k', 'linewidth', 2);
xlabel('Frequency (rad/sec)');
ylabel('X(w)');
title('FREQUENCY SPECTRA');
output