Digital Signal Processing
Assignment : -
Testing Discrete time system properties like
linearity and time invariance
Name : h.madhesh
H.T.No. : 2205A41071
Batch : 03
Implement a discrete-time system in MATLAB with a user-defined
input signal x[n]. Demonstrate the superposition property by
showing that squaring the input signal (n*x2 [n]) results in an output
signal (y[n]) that is also squared. Provide plots to visualize the
input and output signals.
Code :
clc;
clear all;
close all;
n = -10:10;
x = sin(0.2 * pi * n);
y1 = x + 2 * [0, x(1:end-1)];
x2 = x.^2;
y2 = x2 + 2 * [0, x2(1:end-1)];
figure;
subplot(2,2,1);
stem(n, x, 'filled');
title('Input Signal x[n]');
xlabel('n');
ylabel('x[n]');
grid on;
subplot(2,2,2);
stem(n, y1, 'filled');
title('Output Signal y[n]');
xlabel('n');
ylabel('y[n]');
grid on;
subplot(2,2,3);
stem(n, x2, 'filled');
title('Squared Input Signal n*x[n]^2');
xlabel('n');
ylabel('x^2[n]');
grid on;
subplot(2,2,4);
stem(n, y2, 'filled');
title('Output Signal Corresponding to Squared Input');
xlabel('n');
ylabel('y[n] for Squared Input');
grid on;
Input and Output waveforms :
Develop a discrete-time system in MATLAB with a fixed impulse
response h[n]. Test the system using different time-shifted input
signals (x[n - k]) and verify whether the output signals (y[n - k])
remain time-invariant. Provide plots to compare the original and
time-shifted output signals.
Code :
clc;
clear all;
close all;
n = -10:10;
h = (n >= 0) .* (0.9).^n;
x = (n >= 0 & n <= 5);
y = conv(x, h, 'same');
k = 3;
x_shifted = (n >= k & n <= k + 5);
y_shifted = conv(x_shifted, h, 'same');
figure;
subplot(2,2,1);
stem(n, x, 'filled');
title('Original Input Signal x[n]');
xlabel('n');
ylabel('x[n]');
grid on;
subplot(2,2,2);
stem(n, y, 'filled');
title('Original Output Signal y[n]');
xlabel('n');
ylabel('y[n]');
grid on;
subplot(2,2,3);
stem(n, x_shifted, 'filled');
title(['Shifted Input Signal x[n-', num2str(k), ']']);
xlabel('n');
ylabel(['x[n-', num2str(k), ']']);
grid on;
subplot(2,2,4);
stem(n, y_shifted, 'filled');
title(['Shifted Output Signal y[n-', num2str(k), ']']);
xlabel('n');
ylabel(['y[n-', num2str(k), ']']);
grid on;
figure;
stem(n, y, 'r', 'filled'); hold on;
stem(n, y_shifted, 'b', 'filled');
title('Comparison of Original and Shifted Output Signals');
xlabel('n');
ylabel('y[n]');
legend('Original Output', ['Shifted Output y[n-', num2str(k), ']']);
grid on;
Input and Output waveforms :