Lab_4
Lab_4
Z TRANSFORM
Submitted by
- Header/Footer Yes No
- Spelling Yes No
Total Score
Date:
Signature
List of Figures
Figure 1. Console output of Problem 1 10
𝑋(𝑧) = ∑ 𝑥 [𝑛]𝑧 −𝑛
𝑛=−∞
where z is a complex variable. For causal sequences where x[n] = 0 for n < 0, this becomes:
∞
𝑋(𝑧) = ∑ 𝑥 [𝑛]𝑧 −𝑛
𝑛=0
This relationship allows frequency domain analysis of discrete-time systems using the unit circle
in the z-plane.
Experimental Procedure
Problem 1: Partial Fraction Expansion
Objective: Express rational Z-transform functions in partial fraction form to facilitate inverse
transformation.
Given Functions:
12𝑧 −1 +38𝑧 −2+11𝑧 −3+54𝑧 −4
• 𝑋1 (𝑧) = 1−5𝑧 −1 +6𝑧 −2
2𝑧 2 +𝑧−1
• 𝑋2 (𝑧) = 𝑧 2−3𝑧+2
5−11𝑧 −1
• 𝑋3 (𝑧) = 1−5𝑧 −1+6𝑧 −2
Procedure:
1. Convert to positive powers of z when necessary
2. Factor the denominator polynomial
3. Use MATLAB's residue function for partial fraction decomposition
4. Verify results using symbolic computation
5. Apply inverse Z-transform to obtain time-domain sequences
Problem 2: Z-Transform Computation
Objective: Compute Z-transforms of various discrete-time sequences using MATLAB's
symbolic toolbox.
Test Sequences:
• ℎ1 [𝑛] = 0.8𝑛 𝑢[𝑛]
• ℎ2 [𝑛] = 𝑢[𝑛] − 𝑢[𝑛 − 10]
Implementation Steps:
1. Compute the Z-transform of the impulse response
2. Determine the system transfer function H(z)
3. Calculate output using both convolution and Z-transform methods
4. Compare results for verification
Problem 1:
clear all; syms z n;
n_vals = 0:20;
x1_num = zeros(size(n_vals));
for k = 1:length(n_vals)
n_val = n_vals(k);
for i = 1:length(Q1)
if n_val == (i-1)
x1_num(k) = x1_num(k) + Q1(i);
end
end
if n_val >= 0
for i = 1:length(R1)
x1_num(k) = x1_num(k) + R1(i) * (P1(i))^n_val;
end
end
end
fprintf('x1[n] = ');
for i = 1:length(R1)
if i == 1
fprintf('%.0f·%.0f^n', R1(i), P1(i));
else
if R1(i) >= 0
fprintf(' + %.0f·%.0f^n', R1(i), P1(i));
else
fprintf(' %.0f·%.0f^n', R1(i), P1(i));
end
end
end
if Q1(1) ~= 0
fprintf(' + %.0f·δ[n]', Q1(1));
end
x2_num = zeros(size(n_vals));
for k = 1:length(n_vals)
n_val = n_vals(k);
if n_val == 0 && ~isempty(K2)
x2_num(k) = x2_num(k) + sum(K2);
end
if n_val >= 0
for i = 1:length(R2)
if abs(P2(i)) < 1e-10
if n_val == 0
x2_num(k) = x2_num(k) + R2(i);
end
else
x2_num(k) = x2_num(k) + R2(i) * (P2(i))^n_val;
end
end
end
end
x3_num = zeros(size(n_vals));
for k = 1:length(n_vals)
n_val = n_vals(k);
if n_val == 0 && ~isempty(K3)
x3_num(k) = x3_num(k) + sum(K3);
end
if n_val >= 0
for i = 1:length(R3)
x3_num(k) = x3_num(k) + R3(i) * (P3(i))^n_val;
end
end
end
fprintf('x3[n] = ');
for i = 1:length(R3)
if i == 1
fprintf('%.0f·%.0f^n', R3(i), P3(i));
else
if R3(i) >= 0
fprintf(' + %.0f·%.0f^n', R3(i), P3(i));
% Plot results
figure('Position', [100, 100, 1200, 400]);
subplot(1,3,1);
stem(n_vals, x1_num, 'b', 'filled', 'LineWidth', 1.5);
title('x_1[n] = 2·2^n + 12·3^n + 29·δ[n]');
xlabel('n'); ylabel('Amplitude'); grid on;
subplot(1,3,2);
stem(n_vals, real(x2_num), 'r', 'filled', 'LineWidth', 1.5);
title('x_2[n] = 5·(-2)^n/9 + 19/9');
xlabel('n'); ylabel('Amplitude'); grid on;
subplot(1,3,3);
stem(n_vals, real(x3_num), 'g', 'filled', 'LineWidth', 1.5);
title('x_3[n] = -1·2^n + 6·3^n');
xlabel('n'); ylabel('Amplitude'); grid on;
Problem 2:
clear all; close all;
syms n z w0;
subplot(2, 2, 1);
stem(n_vals, h1_num, 'b', 'filled', 'LineWidth', 1.5);
title('h_1[n] = 0.8 u[n]');
xlabel('n'); ylabel('h_1[n]'); grid on; ylim([0, 1]);
subplot(2, 2, 2);
stem(n_vals, h2_num, 'r', 'filled', 'LineWidth', 1.5);
title('h_2[n] = u[n] - u[n-10]');
xlabel('n'); ylabel('h_2[n]'); grid on; ylim([0, 1.5]);
subplot(2, 2, 3);
stem(n_vals, h3_num, 'g', 'filled', 'LineWidth', 1.5);
title('h_3[n] = cos(\omega_0 n) u[n], \omega_0 = \pi/4');
xlabel('n'); ylabel('h_3[n]'); grid on; ylim([-1.5, 1.5]);
subplot(2, 2, 4);
stem(n_vals, h4_num, 'm', 'filled', 'LineWidth', 1.5);
title('h_4[n] = 0.8 cos(\omega_0 n) u[n], \omega_0 = \pi/4');
xlabel('n'); ylabel('h_4[n]'); grid on; ylim([-1, 1]);
sgtitle('Time-Domain Sequences');
% Convolution method
y_conv = conv(x, h, 'full');
y_conv = y_conv(1:length(n_num));
% Z-Transform method
H = 1 + z^-1 + z^-2;
x_sym = cos(2*pi*n/3) * (heaviside(n) - heaviside(n-14));
X = ztrans(x_sym, n, z);
Y = H * X;
y_ztrans = iztrans(Y, n);
y_ztrans_num = double(subs(y_ztrans, n, n_num));
% Plot comparison
figure;
stem(n_num, y_conv, 'b', 'filled'); hold on;
stem(n_num, y_ztrans_num, 'r--');
title('FIR Filter Output: Convolution vs Z-Transform');
xlabel('n'); ylabel('y[n]');
legend('Convolution', 'Z-Transform');
grid on;
% Verify results
disp('Difference between Convolution and Z-Transform outputs:');
disp(max(abs(y_conv - y_ztrans_num)));
Result
syms z;
X_z = z/(z - 0.8);
H_a = (1 + z^(-1)) / (1 + 1.5*z^(-1) + 0.5*z^(-2));
Y_a_z = simplify(H_a * X_z);
fprintf('Y_a(z) = '); disp(Y_a_z);
% Plot solutions
figure('Position', [100, 400, 1200, 600]);
subplot(2,2,1);
stem(n_vals, x_input, 'k', 'filled', 'LineWidth', 1.5);
title('Input: x[n] = (0.8)^n u[n]');
xlabel('n'); ylabel('x[n]'); grid on;
subplot(2,2,2);
stem(n_vals, y_a, 'b', 'filled', 'LineWidth', 1.5);
title('Solution (a): y_a[n]');
xlabel('n'); ylabel('y_a[n]'); grid on;
subplot(2,2,3);
stem(n_vals, y_b, 'r', 'filled', 'LineWidth', 1.5);
title('Solution (b): y_b[n]');
xlabel('n'); ylabel('y_b[n]'); grid on;
subplot(2,2,4);
plot(n_vals, x_input, 'k-', 'LineWidth', 2); hold on;
plot(n_vals, y_a, 'b--', 'LineWidth', 2);
plot(n_vals, y_b, 'r:', 'LineWidth', 2);
title('Comparison of Input and Outputs');
xlabel('n'); ylabel('Amplitude');
legend('x[n]', 'y_a[n]', 'y_b[n]'); grid on;
n_check = 2:length(y_b);
left_b = y_b(n_check) - y_b(n_check-1);
right_b = x_input(n_check) + x_input(n_check-1);
error_b = max(abs(left_b - right_b));
fprintf('Part b verification error: %.2e\n', error_b);
Result
System Analysis: Z-transform analysis of the FIR filter revealed important frequency domain
characteristics, with the transfer function providing insights into system behavior that
complemented time-domain convolution results.
The fundamental relationship between poles, zeros, and system stability was consistently
observed throughout all experiments. Poles inside the unit circle corresponded to stable systems,
while the location of zeros determined frequency response characteristics. The Z-transform's
ability to convert convolution operations into simple multiplication greatly simplified system
analysis.
The Z-transform principles demonstrated in this lab are essential for digital filter design, system
stability analysis, and real-time signal processing applications. Understanding these concepts is
crucial for designing digital controllers, implementing recursive filters, and analyzing discrete-
time system performance.
The systematic approach to problem-solving using Z-transform techniques enhanced our
understanding of both theoretical foundations and practical implementation strategies essential
for advanced digital signal processing applications.
THE END