Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Lab - Assignment1 Signals and Systems

Lab_Assignment1 signals and systems

Uploaded by

hajermmjaber55
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab - Assignment1 Signals and Systems

Lab_Assignment1 signals and systems

Uploaded by

hajermmjaber55
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

ELEC 351 Signals and Systems

Lab Exercise # 1
Date 11/2/2024
Group # 6

Name Student ID Participation


Percentage
Alya Yousef 202106180 [ 50%]
Hajer Jaber 201708749 [ 50%]

Grading Rubric

Completeness of the report Grading


scheme
Organization of the report 10%
Clear PDF, with cover sheet, answers are in the same order
as questions in the assignment, copies of the questions
Quality of figures 10%
Correctly labeled with title, x-axis, y-axis, and name(s)
Understanding of the questions and provide a complete 80%
answers (16 mark for each question)

Note: solve the following questions using either MATLAB or python.

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)');

• 𝑥(𝑡) = 𝑢(𝑡 − 5) − 𝑢(𝑡 + 1) + 8𝛿(𝑡 − 3)

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])

2- For the signal 𝑥(𝑡) of Figure(1), Use MATLAB or python to plot:


a. 4𝑥(−𝑡/3)
b. 𝑥(3 + 𝑡)
c. 2𝑥(2𝑡 − 1)
d. −4𝑥(𝑡 − 2)

Code for x(t) :


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);
fplot(X)
title('x(t) VS t');
xlim([-7 4])
ylim([-2 2])
xlabel('time(sec)');
ylabel('x(t)');
grid on;

3
Graph of x(t):

Code for part a :


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/3);
fplot(X1)
title('4x(-t/3) VS time');
xlim([-10 20])
ylim([-6 6])
xlabel('time(sec)');
ylabel('4x(-t/3)');
grid on;

Graph for part a :

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;

Graph for part b :

Code for part c :


subplot(3,1,3)
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=2*X(2*t-1);
fplot(X1)
title('2x(2t-1) VS time');
xlim([-3 3])
ylim([-6 6])
xlabel('time(sec)');
ylabel('2x(2t-1)');
grid on;

Graph for part c :

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;

Graph for part d :

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)

Code & Graph for part (i):


subplot(2,1,2)
t=-6:0.01:6;
u=@(t) heaviside(t);
r=@(t) t.*(t>0);
figure(1);
x=@(t) u(t)-u(t-2);
y=@(t) r(t)-2.*r(t-1)-r(t-2);
plot(t,x(t-2),'LineWidth',2);
ylim([0 1])
xlabel('time (sec)');
6
ylabel('x1(t)'); grid on
title('x1(t) VS time');
y1=y(t-2);
plot(t,y1,'LineWidth',2);
ylim([-5 3])
xlabel('time (s)');
ylabel('y1(t)'); grid on
title('y1(t) VS time')

Code & Graph for part (ii):

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):

Code &graph for a):


clear all;
close all;
clc;
Fs=10000;
dt=1/Fs;

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;

% Plot X(t)conv h(t)


subplot(3,1,3);
plot(t3,y,'linewidth',1);
xlabel('Time');
ylabel('Amplituide');
title('x(t) conv h(t)');
grid on;

9
Code & graph b):
% Clear workspace, close all figures, and clear command window
clear all; close all; clc;

% Sampling frequency and time step


Fs = 300; dt = 1/Fs;

% Define time vector


t = -1:dt:5;

% Define signal A using rectangular pulses


A = -2 * rectpuls(t - 0.5, 1) + 2 * rectpuls(t - 1.5, 1);

% 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)');

% Define Filter B using triangular pulses


B = 2 * tripuls(t - 1, 2) - 2 * tripuls(t - 3, 2);

% 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)');

% Convolve A and B to get Output C


C = dt * conv(B, A);

% Adjust time vector for convolution result


tn = 2 * min(t):dt:2 * max(t);

% 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

% Set sampling frequency and time step


Fs = 1000; dt = 1/Fs;
t = -5:dt:5;

% Define x1(t) as a rectangular pulse from -3 to 3 with an offset of -1


x1 = (0 * (t < -3) + 1 * (t >= -3) + 1 * (t <= 3) + 0 * (t > 3)) - 1;

% 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;

% Define x2(t) as a triangular pulse centered at t = 0 with width of 6


x2 = 3 * tripuls(t, 6);

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

You might also like