clc;
clear;
close all;
% Time index
n = -5:5;
% Input signals
x1 = [0 0 0 1 2 3 2 1 0 0 0];
x2 = [0 0 1 1 1 1 1 1 1 0 0];
% Constants
a = 2;
b = 3;
% Left-Hand Side (LHS)
x = a*x1 + b*x2;
%y_lhs = 2*x;
y_lhs = x.^2;
% Right-Hand Side (RHS)
% y1 = 2*x1;
%y2 = 2*x2;
y1 = x1.^2;
y2 = x2.^2;
y_rhs = a*y1 + b*y2;
% Display results
disp('LHS = ');
disp(y_lhs);
disp('RHS = ');
disp(y_rhs);
% Verify linearity
if isequal(y_lhs, y_rhs)
disp('The system is LINEAR.');
else
disp('The system is NON-LINEAR.');
end
% Plot
figure;
subplot(2,1,1);
stem(n, y_lhs, 'filled');
title('LHS = T[a x_1[n] + b x_2[n]]');
xlabel('n');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
stem(n, y_rhs, 'filled');
title('RHS = aT[x_1[n]] + bT[x_2[n]]');
xlabel('n');
ylabel('Amplitude');
grid on;
To embed this project on your website, copy the following code and paste it into your website's HTML: