Lab - Assignment1 Signals and Systems
Lab - Assignment1 Signals and Systems
Lab Exercise # 1
Date 11/2/2024
Group # 6
Grading Rubric
1
1- Use MATLAB or python to generate plots of the following continues-time signals for −10 ≤ t ≤ 10:
• 𝑥(𝑡) = 𝛿(𝑡)
t=-10:0.1:10;
impulse= t==0;
stem(t,impulse,'linewidth',2);grid on
ylim([0 1])
xlabel('t');
ylabel('x(t)');
title('x(t)= δ(t)');
subplot(3,1,2)
t=-10:0.01:10;
impulse = t==3;
x = (t>=5)-(t>=-1)+8* impulse;
plot(time, x2,'-b', 'linewidth',1);
title('x(t) vs time (sec)');
xlabel('time(sec)');
ylabel('x');
ylim([-3 10])
2
• 𝑥(𝑡) = 3[𝑟(−𝑡) + 𝑟(𝑡)] , 𝑟(𝑡): 𝑖𝑠 𝑟𝑎𝑚𝑝 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛
subplot(3,1,2)
t=-10:0.01:10;
x = -3*t.*(t>=-10 & t <= 0)+3*t.*(t>=0 & t <= 10);
plot(time, x,'-b', 'linewidth',2);grid on
title('x(t) vs time (sec)');
xlabel('time(sec)');
ylabel('x(t)');
ylim([0 30])
xlim([-10 10])
3
Graph of x(t):
4
Code for part b :
subplot(2,1,2)
syms X(t) x(t)
X(t)= piecewise((-6 <= t)<-3, (-1/3)*t-2, (-3<= t) < 0, 1,(0<=t)<=3,(-1/3)*t+1);
X1=X(3+t);
fplot(X1)
title('x(3+t) VS time');
xlim([-10 4])
ylim([-2 2])
xlabel('time(sec)');
ylabel('x(3+t)');
grid on;
5
Code for part d :
subplot(2,1,2)
syms X(t) x(t)
X(t)= piecewise((-6 <= t)<-3, (-1/3)*t-2, (-3<= t) < 0, 1,(0<=t)<=3,(-1/3)*t+1);
X1=-4*X(t-2);
fplot(X1)
title('-4x(t-2) VS time');
xlim([-6 6])
ylim([-6 6])
xlabel('time(sec)');
ylabel('-4x(t-2)');
grid on;
3- The input 𝑥(𝑡) and the corresponding output 𝑦(𝑡) of a linear time-invariant (LTI) system are
𝑥(𝑡) = 𝑢(𝑡) − 𝑢(𝑡 − 1) , 𝑦(𝑡) = 𝑟(𝑡) − 2𝑟(𝑡 − 1) + 𝑟(𝑡 − 2)
Determine the outputs 𝑦𝑖 (𝑡), 𝑖 = 1; 2; 3 corresponding to the following inputs
(i) 𝑥1 (𝑡) = 𝑢(𝑡 − 2) − 𝑢(𝑡 − 3);
(ii) 𝑥2 (𝑡) = 𝑢(𝑡 + 3) − 𝑢(𝑡 + 2)
Plot the inputs 𝑥𝑖 (𝑡) and the corresponding output 𝑦𝑖 (𝑡).
What you can notice if we introduce delay into LTI system? Comment.
Hint: use Heaviside and below ramp function to plot the signals or just like
what we did in the lab.You can generate the output manually then plot it.
function r = ramp(x)
r = max(0,x)
subplot(2,1,2)
t=-6:0.01:6;
u=@(t) heaviside(t);
r=@(t) t.*(t>0);
figure(2);
x=@(t) u(t)-u(t-2);
y=@(t) r(t)-2.*r(t-1)-r(t-2);
plot(t,x(t+3),'LineWidth',2);
ylim([0 1])
xlabel('time (sec)');
ylabel('x2(t)'); grid on
title('x2(t) VS time');
y2=y(t+3);
plot(t,y2,'LineWidth',2);
ylim([-4 3])
xlabel('time (s)');
ylabel('y2(t)'); grid on
title('y2(t) VS time')
7
4- For the input signal 𝑥(𝑡), and the impulse response ℎ(𝑡), find the output signal 𝑦(𝑡) for the following
(Hint: Show your answer all graphs and code):
8
t = 0:dt:5;
x=0*(t<1) + 2*(t>=1) - 2*(t>3);
h=0*(t<0)+2*(t>=0)-2*(t > 1)+1*(t>=3).*(-t+5);
y = conv(x,h)*dt;
t3 = 2*min(t):dt:2*max(t);
% Plot X(t)
subplot(3,1,1);
plot(t,x,'linewidth',1);
ylim([-3 3]);
xlabel('Time');
ylabel('Amplituide');
title('X(t)');
grid on;
% Plot h(t)
subplot(3,1,2);
plot(t,h,'linewidth',1);
xlabel('Time');
ylabel('Amplituide');
title('h(t)');
grid on;
9
Code & graph b):
% Clear workspace, close all figures, and clear command window
clear all; close all; clc;
% Plot Signal A
subplot(3,1,1);
plot(t, A, 'r-', 'LineWidth', 2);
ylim([-2.5 2.5]);
grid on;
xlabel('Time (sec)');
ylabel('Signal A');
title('Signal A vs. Time (sec)');
% Plot Filter B
subplot(3,1,2);
plot(t, B, 'k-', 'LineWidth', 2);
ylim([-2.5 2.5]);
grid on;
xlabel('Time (sec)');
ylabel('Filter B');
title('Filter B vs. Time (sec)');
% Plot Output C
subplot(3,1,3);
plot(tn, C, 'm-', 'LineWidth', 2);
xlim([-1 9]);
ylim([-5 5]);
grid on;
xlabel('Time (sec)');
10
ylabel('Output C');
title('Output C vs. Time (sec)');
5- For the following signals 𝑥1(𝑡) and 𝑥2(𝑡) plot each signal and find the convolution
% Plot x1(t)
subplot(3,1,1);
plot(t, x1, 'LineWidth', 2);
ylim([-2 2]);
xlabel('t');
ylabel('x1(t)');
title('x1(t)');
grid on;
11
% Plot x2(t)
subplot(3,1,2);
plot(t, x2, 'LineWidth', 2);
xlabel('t');
ylabel('x2(t)');
title('x2(t)');
grid on;
y = dt * conv(x2, x1);
tn = 2 * min(t) : dt : 2 * max(t);
% Plot y(t)
subplot(3,1,3);
plot(tn, y, 'LineWidth', 2);
xlabel('t');
ylabel('y(t)');
title('y(t)');
grid on;
12