LAB Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Lab Tasks 01: Plot the 𝑦(𝑥) = 𝑥 2 𝑐𝑜𝑠𝑥, 𝑔(𝑥) = 𝑥𝑐𝑜𝑠𝑥, 𝑓(𝑥) = 2𝑥 𝑠𝑖𝑛𝑥 in the same

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.

We know, y(t)=e3jt = cos(3t)+jsin(3t)

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

title('Real part: cos(3t)')

xlabel('Time')

ylabel('Amplitude')

subplot (2,1,2);

plot(y,'g');

title('Imaginary part: sin(3t)')

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

title('Both Cosine & Sine Wave')

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

title('x(t)= Ae^B1t and y(t)= Ae^B2t togather')

xlabel('Time')

ylabel('Amplitude')

1. Consider the signal x(t)= t 𝑒 −0.1𝑡 cos(t) , 0 ≤ t ≤ 20. Plot


a) the signal x(t)
b) even decomposition
c) odd decomposition
d) the signal y(t) = xe(t) + xo(t)

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

4. Verify that, a) z[n]= sin(πn+2) + cos (2πn/3 +1) is periodic.


b) z[n] = sin(πn+2) + cos (2n/3 +1) is periodic/aperiodic.

Lab Tasks 3.4(a):


Code:
clc;
clear all;
close all;
t=0:0.001:24;
x=sin((pi*t)+2)+cos(((2*pi*t)/3)+1);
y=sin((pi*(t+6))+2)+cos(((2*pi*(t+6))/3)+1);
subplot(2,1,1);
plot(t,x,'g');
title('x(t)=sin((pi*t)+2)+cos(((2*pi*t)/3)+1)');
xlabel('Time');
ylabel('Amplitude');
subplot(2,1,2);
plot(t,y,'b');
title('x(t+6)=sin((pi*(t+6))+2)+cos(((2*pi*(t+6))/3)+1)');
xlabel('Time');
ylabel('Amplitude');
Output : The function is periodic.
Lab Tasks 3.4(b):
Code:
clc;
clear all;
close all;
t=0:0.001:24*pi;
x=sin((pi*t)+2)+cos(((2*t)/3)+1);
y=sin((pi*(t+6))+2)+cos(((2*(t+6))/3)+1);
subplot(2,1,1);
plot(t,x,'g');
title('x(t)=sin((pi*t)+2)+cos(((2*t)/3)+1)');
xlabel('Time');
ylabel('Amplitude');
subplot(2,1,2);
plot(t,y,'b');
title('x(t+6)=sin((pi*(t+6))+2)+cos(((2*(t+6))/3)+1)');
xlabel('Time');
ylabel('Amplitude');

Output : The function is not periodic.

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

3. Compute the convolution between the complex sequence


x = [3+2j, 1+j, 4+6j], and h = [1-2j, j,3-2j,2 ] .
Code:
clc;
clear all;
close all;
h=[1-2i i 3-2i 2];
x=[3+2i 1+i 4+6i];
y=conv(x,h);
stem(y);title("Convution output");
4. a) A system is described by the impulse response, h [n] = e-2n u[n − 1].

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

5. A discrete-time system is described by the impulse response h[ n] = 0.8 n , 0 ≤ n ≤ 10.


Without using conv command compute and plot the response of the system to the input signal
x[ n] = √ 1/n, 1 ≤ n ≤ 5.
Code:
clc;
clear all;
close all;
x=[1 1/2 1/3 1/4 1/5];
h=[1 0.8 0.64 0.512 0.4096 0.32768 0.262144 0.2097152
0.16777216 0.134217728 0.107374];
n1=length(x);
n2=length(h);
N=n1+n2-1;
x=[x,zeros(1,N-n1)];
h=[h,zeros(1,N-n2)];
y=zeros(1,N);
for n=1:N
for k=1:n
y(n)=y(n)+x(n)*h(n-k+1);
end
end
disp(y);
ny=0:N-1;
subplot(3,1,1);stem(ny,x);title('input signal x');
subplot(3,1,2);stem(ny,h);title('impulse signal h');
subplot(3,1,3);stem(ny,y);title('response of the system');

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]

Lab Tasks 7.1(a):


Code:
clc;
clear all;
close all;
a=[1, -1.143, 0.4128];
b=[0.0675, 0.1349, 0.675];
x=zeros(1,50);
zi=filtic(b,a,[1, 2]);
y=filter(b,a,x,zi);
yt=impulse(b,a);
yl=stepz(b,a);
subplot(3,1,1)
stem(y,'r');
title('Output Responce');
subplot(3,1,2)
stem(yt,'g');
title('Impulse Responce');
subplot(3,1,3)
stem(yl,'b');
title('Step Responce');
Lab Tasks 7.1(b):
Code:
clc;
clear all;
close all;
a=[1 -0.5];
b=[2];
x=zeros(1,50);
zi=filtic(b,a,[1, 2]);
y=filter(b,a,x,zi);
yt=impulse(b,a);
yl=stepz(b,a);
subplot(3,1,1)
stem(y,'r');
title('Output Responce');
subplot(3,1,2)
stem(yt,'g');
title('Impulse Responce');
subplot(3,1,3)
stem(yl,'b');
title('Step Responce');

Lab Tasks 7.1(c):


Code:
clc;
clear all;
close all;
a=[1 0 -0.11];
b=[1];
x=zeros(1,50);
zi=filtic(b,a,[1, 2]);
y=filter(b,a,x,zi);
yt=impulse(b,a);
yl=stepz(b,a);
subplot(3,1,1)
stem(y,'r');
title('Output Responce');
subplot(3,1,2)
stem(yt,'g');
title('Impulse Responce');
subplot(3,1,3)
stem(yl,'b');
title('Step Responce');

Lab Tasks 7.1(d):


Code:
clc;
clear all;
close all;
a=[1 0.25 -0.125];
b=[1 1];
x=zeros(1,50);
zi=filtic(b,a,[1, 2]);
y=filter(b,a,x,zi);
yt=impulse(b,a);
yl=stepz(b,a);
subplot(3,1,1)
stem(y,'r');
title('Output Responce');
subplot(3,1,2)
stem(yt,'g');
title('Impulse Responce');
subplot(3,1,3)
stem(yl,'b');
title('Step Responce');

Lab Tasks 7.1(e):


Code:
clc;
clear all;
close all;
a=[1 -3/4 0.125];
b=[2];
x=zeros(1,50);
zi=filtic(b,a,[1, 2]);
y=filter(b,a,x,zi);
yt=impulse(b,a);
yl=stepz(b,a);
subplot(3,1,1)
stem(y,'r');
title('Output Responce');
subplot(3,1,2)
stem(yt,'g');
title('Impulse Responce');
subplot(3,1,3)
stem(yl,'b');
title('Step Responce');

2. Use MATLAB comman ‘impz’ to determine the first 30 values of the


IMPULSE RESPONSE for the systems

Lab Tasks 7.2(a):


Code:
clc;
clear all;
close all;
a=[-0.1, 0.4; 0.4, -0.1];
b=[2; 4];
c=[0.5, 0.5];
d=2;
sys=ss(a,b,c,d,-1);
T=[-0.5, 0.5; 0.5, 0.5];
sysT=ss2ss(sys,T);
h=impulse(sys,30);
hT=impulse(sysT,30);
subplot(2,1,1);
stem(h);
title('Original System Impulse Response');
xlabel('Time');
ylabel('Amplitude');
subplot(2,1,2);
stem(hT);
title('Transformed System Impulse Response');
xlabel('Time');
ylabel('Amplitude');

Lab Tasks 7.2(b):


Code:
clc;
clear all;
n=30;
num=[1 0 -0.11];den=[1];
u=heaviside(n); x=u;
zi=filtic(den, num, [1, 2]);
y=filter(den,num,x,zi);
[imp]=impz(den,num,n);
stem([imp],'r');
title('Impulse Response');

Lab Tasks 7.2(c):


Code:
clc;
clear all;
n=30;
num=[1 -0.25 -0.125];den=[1 1];
u=heaviside(n);
x=2^n.*u;
zi=filtic(den, num, [-1, 2]);
y=filter(den,num,x,zi);
[imp]=impz(den,num,n) ;
stem([imp],'r')
title('Impulse Response');
Lab Tasks 7.2(d):
Code:
clc;
clear all;
n=30;
num=[1 -3/4 -1/8];den=[2];
u=heaviside(n);
x=2.*u;
zi=filtic(den, num, [-1, -1]);
y=filter(den,num,x,zi);
[imp]=impz(den,num,n) ;
stem([imp],'r')
title('Impulse Response');

1. Use the MATLAB command ‘ss2ss’ to solve the problems

Lab Tasks 8.1(a):


Code:
clc;
clear all;
close all;
a=[1, -0.5; 1/3, 0];
b=[1; 2];
c=[0.5, 0.5];
d=0;
sys=ss(a,b,c,d,-1);
T=[2, 0; 0, 3];
sysT=ss2ss(sys,T)

Lab Tasks 8.1(b):


Code:
clc;
clear all;
close all;
a=[1, -0.5; 1/3, 0];
b=[1; 2];
c=[0.5, 0.5];
d=0;
T=[0, 3; 2, 0];
sys=ss(a,b,c,d,-1);
sysT=ss2ss(sys,T)

2. Use the MATLAB commands ‘Lsim’ and ‘Impulse’ to determine the first 30

output,

Lab Tasks 8.2(a):


Code:
clc;
clear all;
close all;
a=[0.5, -0.5; 1/3, 0];
b=[1; 2];
c=[1, -1];
d=0;
sys=ss(a,b,c,d,-1);
response=impulse(sys,30);
stem([0:30],response,'g');
title('Impusle Response');
xlabel('Time');
ylabel('Amplitude');

Lab Tasks 8.2(b):


Code:
clc;
clear all;
close all;
a=[0.5, -0.5; 1/3, 0];
b=[1; 2];
c=[1, -1];
d=0;
T=[1, 1; 2, -1];
sys=ss(a,b,c,d,-1);
sysT=ss2ss(sys,T);
response=impulse(sysT,30);
stem([0:30],response,'r')
title('Impusle Response After Transformation');
xlabel('Time');
ylabel('Amplitude');

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

You might also like