t = -5:0.01:10;
u = double(t>=0);
x = exp(-0.5*t).*u;
x_1 = exp(-0.5*(t-2)) .* double((t-2)>=0); #x_1 = x(t-2)
x_2 = -1*exp(-0.5*(t)) .* double((t)>=0);
plot(t, x_2);
grid on;
title("signal x(t)"); xlabel("t"); ylabel("x")
#------------------------------
t = 0:0.01:10;
x_1 = sin ((2*pi/10)*t);
x_2 = cos((2*pi/10)*t);
T = @(x) 2*x; # x can be any arbitrary input
y_1 = T(x_1)
y_2 = T(x_2)
x_3 = x_1 + x_2
y_3_hat = T(x_3) # the system responds to the linear combination of inputs
y_3 = y_1 + y_2 #the same linear combination of output
threshold = 1e-3;
max_difference = max (abs(y_3 - y_3_hat));
if max_difference < threshold:
disp("y=2x is a linear system")
else:
disp("y=2x is not a linear system");
end
#------------------------------
t = 0:0.01:10;
x = sin(2*pi*t) + 0.5*cos(pi*t);
T = @(x) 2*x;
t0 = 1;
x_shifted = sin(2*pi*(t-t0)) + 0.5*cos(pi*(t-t0));
y_shifted = T(x_shifted); #the response of the system to x_shifted
y_2 = 2*x_shifted; #y_2 = y(t-t0) = 2tx(t-t0) = 2x_shifted
#check if y2 == y_shifted
max_difference = max( abs(y_2 = y_shifted));
if max_difference < threshold:
dis("y=2x is a Time invariant system");
else:
disp("y=2x is not a Time variant system");
To embed this project on your website, copy the following code and paste it into your website's HTML: