LAB Final
LAB Final
LAB Final
figure.
clc;
clear all;
close all;
x=0:1:20;
y=((x.^2).*cos(x));
subplot(3,1,1)
plot(x,y,'b')
title('y(x)=x^2cosx')
xlabel('x')
ylabel('y(x)')
x=0:1:20;
g=(x.*cos(x));
subplot(3,1,2)
plot(x,g,'r')
title('g(x)=xcosx')
xlabel('x')
ylabel('g(x)')
x=0:1:20;
f=2.^x;
subplot(3,1,3)
plot(x,f,'g')
title('f(x)=2^x')
xlabel('x')
ylabel('f(x)')
1, −2≤𝑡 ≤2
Lab Tasks 02: Plot the following function, f(t)={ 0, 2≤𝑡≤5
𝑡𝑠𝑖𝑛(4𝜋𝑡) 5≤𝑡≤8
clc;
clear all;
close all;
subplot(3,1,1)
plot([-2 2],[1 1],'r')
title('f(t)=1')
xlabel('t')
ylabel('f(t)')
subplot(3,1,2)
plot([2 5],[0 0],'g')
title('f(t)=0')
xlabel('t')
ylabel('f(t)')
t=5:0.1:8;
f=(t.*sin(4*pi*t))
subplot(3,1,3)
plot(t,f,'b')
title('f(t)=t*sin(4*pi*t)')
xlabel('t')
ylabel('f(t)')
𝜋
Lab tasks 03: Write a command to plot 𝑥[𝑛] = 𝑐𝑜𝑠 (0.5𝜋𝑛 + ) + sin (0.5𝜋𝑛).
3
Editor Code:
clc;
clear all;
close all;
n=-20:1:20;
x=(cos((0.5*pi*n)+(pi/3))+sin(0.5*pi*n));
stem(n,x,'r');
title('x[n]=cos((0.5*pi*n)+(pi/3))+sin(0.5*pi*n)')
;
xlabel('n')
ylabel('x[n]')
Lab Tasks 04: Plot the discrete function f[n]= 𝑛2 , where -20≤n≤20.
Editor Code:
clc;
clear all;
close all;
n=-20:1:20;
f=n.^2;
stem(n,f,'r');
title('f[n]=n^2');
xlabel('n')
ylabel('f[n]')
Lab Tasks 1: Define and plot the signal, x(t) = cos(πt).
Code:
clc;
clear all;
close all;
t=0:0.005:20;
x=cos(pi*t);
plot(t,x,'g')
title('Cosine Wave')
xlabel('Time')
ylabel('Amplitude')
Lab Tasks 2: To define and plot the real and the imaginary part of the signal, y(t)=e3jt in the time of two
periods.
Code:
clc;
w=3;
T=(2*pi)/w;
t = 0:0.001:2*T;
x = cos(3*t);
y = sin(3*t);
subplot (2,1,1);
plot(x,'b');
xlabel('Time')
ylabel('Amplitude')
subplot (2,1,2);
plot(y,'g');
xlabel('Time')
ylabel('Amplitude')
Lab Tasks 3: Plot the signal, x(t)= 3cos(3πt+π/3) in four periods.
Code:
clc;
clear all;
close all;
w=(3*pi);
T=(2*pi)/w;
t=0:0.005:4*T;
x=3*cos(3*pi*t+pi/3);
plot(t,x,'g')
title('Cosine Wave')
xlabel('Time')
ylabel('Amplitude')
Lab Tasks 4: Plot the following two signals together in the same plot, x1(t)=cos(t), x2(t)=sin(t+π/2).
Code:
clc; t = 0:0.001:4*pi;
x1 = cos(t);
subplot (3,1,1);
plot(x1,'b');
title('Cosine Wave')
xlabel('Time')
ylabel('Amplitude')
x2 = sin(t+pi/2);
subplot (3,1,2);
plot(x2,'g');
title('Sine Wave')
xlabel('Time')
ylabel('Amplitude')
subplot (3,1,3);
plot(x1,'b');
hold on phi=pi/2;
plot(x2,'g');
xlabel('Time')
ylabel('Amplitude')
Lab Tasks 5: To plot the Signal x(t)= AeB1t and y(t)= AeB2t in the time interval –T< t< T, where A= Roll
Number, B1=A/100, B2=-A/100 and T=A/2.
clc;
clear all;
close all;
A=6; B1=A/100;
B2=-B1;
T=A/2;
t=-T:0.01:T;
x=A*exp(B1*t) y=A*exp(B2*t);
subplot(3,1,1);
plot(t,x,'b');
title('x(t)= Ae^B1t')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,2);
plot(t,y,'g');
title('y(t)= Ae^B2t')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,3);
plot(t,x,'b');
hold on
plot(t,y,'g');
xlabel('Time')
ylabel('Amplitude')
Lab Tasks 1: Plot the signal x(t)= t 𝑒 ି.ଵ௧ cos(t) ; 0 ≤ t ≤ 20.Also determine the odd and
even decomposition.
Code:
clear all;
close all;
t=(0:0.1:20);
e=exp(-0.1*t);
x=t.*e.*cos(t);
plot(t,x,'r')
title('x(t)= t e^(-0.1t) cos(t) ')
xlabel('Time')
ylabel('Amplitude')
Even decomposition:
Code:
clc;
clear all;
close all;
figure(1)
t=0:0.1:20;
xe=(0.5*((t.*exp(-0.1*t).*cos(t)))-
((t.*exp(0.1*t).*cos(t))))
plot(t,xe,'r')
title(' even of x(t)= t e^(-0.1t) cos(t) ')
xlabel('Time')
ylabel('Amplitude')
Odd decomposition:
Code:
clc;
clear all;
close all;
figure(1)
t=0:0.1:20;
xo=(0.5*((t.*exp(-
0.1*t).*cos(t)))+((t.*exp(0.1*t).*cos(t))));
plot(t,xo,'r')
title(' Odd of x(t)= t e^(-0.1t) cos(t) ')
xlabel('Time')
ylabel('Amplitude')
Code:
clc;
clear all;
close all;
figure(1)
t=0:0.1:20;
xe=(0.5*((t.*exp(-
0.1*t).*cos(t)))+((t.*exp(0.1*t).*cos(t))));
xo=(0.5*((t.*exp(-
0.1*t).*cos(t)))+((t.*exp(0.1*t).*cos(t))));
y=xe+xo;
plot(t,y,'r')
title(' y(t)=xe+xo')
xlabel('Time')
ylabel('Amplitude')
t, 0 ≤ t ≤ 2
2.Suppose that, x(t)= { } . Plot the signals, x(t), x(-t), x(t/2), x(2+4t) and x(-
4 − t, 2 ≤ t ≤ 4
2-4t).
Code:
clc;
clear all;
close all;
t=0:0.01:2;
y=t;
t1=2:0.01:4;
y1=4-t1;
subplot(511)
plot(t,y);hold on;plot(t1,y1,'b');title("x(t)");
t2=-4:0.01:-2;
y2=t2+4;
t3=-2:0.01:0;
y3=-t3;
subplot(512);plot(t2,y2,'b');hold on;plot(t3,y3);title("x(-
t)");
t4=0:0.01:4;
y4=0.5*t4;
t5=4:0.01:8;
y5=4-t5*0.5;
subplot(513);plot(t4,y4);hold
on;plot(t5,y5,'b');title("x(t/2)");
t6=-0.5:0.01:0;
y6=t6*4+2;
t7=0:0.01:0.5;
y7=2-t7*4;
subplot(514);plot(t6,y6);hold
on;plot(t7,y7,'b');title("x(2+4t)");
t8=-1.5:0.01:-1;
y8=t8*4+6;
t9=-1:0.01:-0.5;
y9=-2-t9*4;
subplot(515);plot(t8,y8);hold on;plot(t9,y9,'b');title("x(-
2-4t)");
Lab Tasks 3.3: Plot the signal x(t)= cos(t)+ sin(3t) in time of three periods.
Code:
clc;
clear all;
close all;
t = 0:0.01:6*pi;
x = cos(t)+sin(3*t);
plot(t,x,'b');
title('x(t)=cos(t)+sin(3*t)');
xlabel('Time');
ylabel('Amplitude');
5. Find, whether the signals x(t)= t 2 and y(t)= t 3 are even or odd.
clc;
clear all;
close all;
t1=0:0.001:8;
t2=-8:0.001:0;
x1=t1.^2;
x2=t2.^2;
x3=-t1.^2;
subplot(2,1,1)
plot(t1,x1,'r',t2,x2,'b',t1,x3,'g');
title('Even Signal');
xlabel('Time');
ylabel('Amplitude');
y1=t1.^3;
y2=t2.^3;
y3=-t1.^3;
subplot(2,1,2);
plot(t1,y1,'r',t2,y2,'b',t1,y3,'g');
title('Odd Signal');
xlabel('Time');
ylabel('Amplitude');
1. A MIMO system is described by the i/o relationships y1(t)= x1(t)+ x2(t)+ x3(t),
and y2(t)= x1(t) -x2(t)+ x3(t). Compute and plot the system response to the input
signals x1(t)=sin(2πt), x2(t)= 2sin(2πt) and x3(t)= sin(6πt) for -10≤n≤10.
Code:
clc;
clear all;
close all;
t=-10:0.01:10;
x1=sin(2*pi*t);
x2=2*sin(2*pi*t);
x3=sin(6*pi*t);
y1=x1+x2;
y2=x1+2+x3;
subplot(311); plot(t,y1,'g');title("y1(t)=x1(t)+x2(t)");
subplot(312);
plot(t,y2,'r');title("y2(t)=x1(t)+x2(t)+x3(t)");
subplot(313); plot(t,y1,'g');hold on;plot(t,y2,'r');
title("y1(t) and y2(t)");
Lab Task 2: Suppose that a MISO system is described by the i/o relationship y(t)=
x1(t)+ x2(t). x3(t)
Compute and plot the system’s output if the input signal are given by, x1(t)= u(t)-
u(t-3), x2(t)= tsint(t), 0 ≤ t ≥ 4 and x3(t)= t cos(t), 0 ≤ t ≥ 4.
Code:
clc;
clear all;
close all;
t=0:0.01:5;
x1=heaviside(t)-heaviside(t-3);
x2=(t).*sin(t);
x3=(t).*cos(t);
y1=x1+(x2).*(x3);
plot(t,y1,'g');
axis([-4 4 -10 10]);
title("y(t)=x1(t)+(x2(t)).*(x3(t))");
Lab Task 3 Suppose that a MIMO system is described by the I/O relationship
y1(t)= x1(t)+ x2(t) and y2(t)= x1(t)- x2(t) .
Compute and plot the system response to the input signals x1 (t) = u(t) and
x2 (t) = 0.5(t).u( t - 1).
Code:
clc;
clear all;
close all;
t=0:0.01:7;
x1=heaviside(t);
x2=(0.5).*(t).*heaviside(t-1);
y1=x1+x2;
y2=x1-x2;
subplot(211);plot(t,y1,'g');axis([-3 7 -5 5]);
title("y1(t)=x1(t)+x2(t)")
subplot(212);plot(t,y2,'g');axis([-3 7 -5 5]);
title("y2(t)=x1(t)-x2(t)")
Lab Task 4 : Suppose that a MISO system S is described by the i/o relationship
y(t)= x1(t){x2(t)+x3(t) }.
Compute and plot the system’s output if the input signals are given by x1(t)=e
2t,0 ≤t ≤5, x2(t)=te t0 ≤t ≤5, and x3(t)=cos(t), 0 ≤t ≤5.
Code:
clc;
clear all;
close all;
t=0:0.01:5;
x1=exp(2.*t);
x2=(t).*exp(t);
x3=cos(t);
y1=(x1).*((x2)+(x3));
plot(t,y1,'b');
title("y(t)=x1(t)*[x2(t))+(x3(t)]");
Lab Task 5: A MIMO system is described by the i/o relationships y1[n ] =x1[n ] /x2[
n] and y2[n ]=x1[ n] .x2[n ]. Compute and plot the system response to the input
signals x1[n ]=u[n] and x2[n]=n2 for -10≤n≤10 .
Code:
clc;
clear all;
close all;
t=0:0.01:3*pi;
x1=heaviside(t);
x2=t.^2;
y1=cos(2*t);
y2=(x1).*(x2);
subplot(211);plot(t,y1,'r');
title("y1=(x1)/(x2)");
subplot(212);plot(t,y2,'r');
title("y1=(x1)*(x2");
a) Using the input signal x(t)= u(t)-u(t-1) find out if the system described by the I/O relationship,
y(t)=3 x(t) and y(t)=x(t-1) are static or dynamic using MATLAB.
Code:
clc;
close all;
clear all;
t=-2:0.01:2;
x=heaviside(t)-heaviside(t-1);
y1=3*x;
y2=heaviside(t-1)-heaviside(t-2);
subplot(2,1,1);
plot(t,y1,'g');
title('Plotting y(t)=3x(t)');
xlabel('Time');
ylabel('Amplitude');
subplot(2,1,2);
plot(t,y2,'r');
title('Plotting y(t)=x(t-1)');
xlabel('Time');
ylabel('Amplitude');
b) Determine if the discrete-time system described by the I/O relationship y[n]= x2 and
y[n]=x[ n/2]are static or dynamic. Use the input signal x[n ]= [ 0 1 2 3 4], -1 ≤n ≤3.
Code:
clc;
close all;
clear all;
n=-5:1:9;
x=n+1;
y1=x.*x;
n1=-2:1:6;
y2=[0 0 1 0 2 0 3 0 4];
subplot(2,1,1);
stem(n,y1,'r');
title('Plotting y[n]=x^2');
xlabel('Time [n]');
ylabel('Amplitude');
subplot(2,1,2);
stem(n1,y2,'b');
title('Plotting y[n]=x[n/2]');
xlabel('Time [n]');
ylabel('Amplitude');
2. Let x1(t)=u(t)– u(t-2) be input signals to the systems described by the I/O relationship
y(t)=2x(t) and y(t)=x2(t). Determine if the linearity property holds for these two systems.
Code:
clc;
clear all;
close all;
t=-10:0.01:10
x1=heaviside(t)-heaviside(t-2)
x2=heaviside(t-2)-heaviside(t-5)
y1=2*x1
y2=2*x2
subplot(2,1,1);
xlabel('y1+y2')
ylabel('Amplitude');
plot(t, y1+y2);xlabel('y1+y2');ylabel('Amplitude');
subplot(2,1,2);x=x1+x2;y=2*x;
plot(t, y);xlabel('y=2x');ylabel('Amplitude')
figure;
x3=heaviside(t)-heaviside(t-2)
x4=heaviside(t-2)-heaviside(t-5)
y3=x3.*x3
y4=x4.*x4
subplot(2,1,1)
plot(t, y3+y4)
subplot(2,1,2)
xx=x3+x4
yy=xx.*xx; plot(t, yy)
3. The response of a system S to an input signal x(t) is y(t)=te–t x(t). Determine if this system is
time invariant by using the input signal x(t)= u(t)-u(t-5).
Code:
clc;
clear all;
close all;
t=-20:0.01:20
x=heaviside(t)-heaviside(t-5)
y=t.*exp(-t).*x
subplot(2,1,1)
plot(t,x,t,y,'r')
x1=heaviside(t-5)-heaviside(t-10)
y2=t.*exp(-t).*x1
subplot(2,1,2)
plot(t,x1,t,y2,'g')
4. Suppose that an input signal x(t)=cos(2π) is applied to two system described by the I/O
relationship y1[t]=x2 [t ] and y2(t)=t x(t). Determine if these two system is stable.
Code:
clc;
clear all;
close all;
t = -10:0.01:10;
x = cos(2*pi*t)
y1 = x.*x;
y2 = t.*x
plot(t,x,t,y1,t,y2);
legend('x(t)','y1(t)','y2(t)')
5. Find out if the discrete-time system described by the i/o relationship y[ n] =x[ -n] for the input
signal x[n] = 2n, -2≤n≤2 is
a) Static or dynamic
b) Causal or noncausal
c) Linear or not linear
d) Shift invariant or shift variant
clc;
clear all;
close all;
n = -2:0.1:2
x = 2*n;
y = 2 * -n;
stem(n,y);
figure;
x1 = x;
y1 = y;
x2 = x ;
y2 = -y;
y3 = y1+y2;
subplot(2,1,1);
stem(n,y3);
xx = x1+x2;
yy = -xx;
subplot(2,1,2);
stem(n,yy);
1 − 𝑡, 0 ≤ 𝑡 ≤ 1
1. A linear time-invariant system is described by the impulse response, h(t)={
0, 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
Code:
clc;
clear all;
close all;
t1=0:0.01:1;
h=1-t1;
t2=0:0.01:2
x=2.*(t2>=0);
y=conv(x,h);
subplot(311); plot(t1,h,'r');title("impulse signal");
subplot(312); plot(t2,x,'b');title("Input signal");
subplot(313); plot(y,'g');title("response");
2. Suppose that a linear time-invariant (LTI) system is described by the impulse response,
h(t) = e-t u(t). Compute the response of the system to the input signal without using conv
0.6 , −1 ≤ 𝑡 ≤ 0.5
command, x(t) = { 0.3, 0.5 ≤ 𝑡 ≤ 3
0, 𝑡 ≤ −1 𝑎𝑛𝑑 𝑡 ≥ 3
Code:
clc;
clear all;
close all;
t=-1:0.01:1;
x=0.6*ones(size(t));
t1=0.5:0.01:3;
x1=0.3*ones(size(t1));
t3=0:0.01:10
h=exp(-t3);
t4=0.5:0.01:10
y1=-0.6*(exp(-t-1)-1);
y2=-0.3*(exp(-t4+0.5)-exp(-t4+3))-0.6*(exp(-t4-1)-exp(-
t4+0.5));
subplot(311);plot(t,x,t1,x1,'r');ylim([0.2
0.7]);title('input signal x');
subplot(312);plot(t3,h,'g');title('impulse signal h');
subplot(313);plot(t,y1,t4,y2,'k');title('response of the
system');
Compute and plot the response of the system to the input signal x[n] = u[n]- u[n-2] .
b) Compute the input of system for which you have computed the system response in the
above task and verify the answer.
Code:
clc;
clear all;
close all;
n=0:0.01:15;
h=exp(-2*n).*heaviside(n-1);
x=heaviside(n)-heaviside(n-2);
y=conv(x,h);
subplot(311); plot(n,h,'r');title("impulse signal");
subplot(312); plot(n,x,'b');title("Input signal");
subplot(313); plot(y,'g');title("resonse");
1. Find the output response, impulse response, step response of the following system
equation using initial condition y[-1] =1, y[-2]=2 and zero input,
a) y[n] = 1.143y[n-1] - 0.4128y[n-2] + 0.0675x[n] + 0.1349x[n-2]
b) y[n] - 1/2*y[n-1] = 2x[n]
c) y[n] - 1/9*y[n-2] = x[n-1]
d) y[n] + 1/4*y[n-1] - 1/8*y[n-2] = x[n] + x[n-1]
e) y[n] - 3/4*y[n-1] + 1/8*y[n-2] = 2x[n]
2. Use the MATLAB commands ‘Lsim’ and ‘Impulse’ to determine the first 30
output,
clc;
clear all;
close all;
t=-20:20;
f=(sin(pi.*t))/pi.*t;
y=fft(f);
plot(t,y)
clc;
clear all;
close all;
t=-20:20;
x=t.*exp(-3*t);
y=fft(x);
figure,plot(abs(y)),title('Magnitude');
figure,plot(angle(y)),title('Phase');
figure,plot(real(y)),title('Real Part');
figure,plot(imag(y)),title('Imaginary Part');
clc;
clear all;
close all;
t=-20:20;
h=exp(-t);
x=exp(-t).*cos(2*pi*t);
z=conv(h,x);