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

Khulna University of Engineering & Technology

Department of Mechatronics Engineering

Sessional Report

Course No. : MTE 2210


Course Title : Systems Simulation
Experiment no. : 02
Name of the experiment: Introduction with System Simulation

Submitted by

Name : Ryan Rahman


Roll no. : 1931005
Year : 2nd
Semester : 2nd
A. Write a MATLAB program to get the output shown below where t0
= 2.

Solution:
Matlab Code:
For step signal,
t=0:0.01:10;
x=heaviside(t-2);
plot(t,x);
xlabel('t');
ylabel('u(t-to)')
axis([-1 5 0 1.5]);
For ramp signal,
t=-20:20;
x=heaviside(t);
r=1+t.*x;
plot(t+2,r)
xlabel('t');
ylabel('x(t)')
axis([0 20 0 20]);
Output:
For step signal,

For ramp signal,


B. Write a MATLAB program to get the following output.

Solution:
Matlab Code:
n=0:1:8;
x=[0 0 1 2 3 4 5 4 3];
subplot(2,1,1)
stem(n,x)
title('x(n) signal')
xlabel('n')
ylabel('x(n)')
subplot(2,1,2)
stem(-n,x)
title('y(n)=x(-n) signal')
xlabel('n')
ylabel('y(n)')

Output:

C. Write a MATLAB program to perform the convolution between X


(n) = [1 2 3 5] and y (n) = [- 1 -2]
Solution:
Matlab Code:
X=[1 2 3 5];
y=[-1 -2];
convolution=conv(X,y);
disp(convolution)
subplot(3,1,1);
stem(X,'g');
xlabel('discrete time');
ylabel('X(n)');
title('1st sequence');
subplot(3,1,2);
stem(y,'r');
xlabel('discrete time');
ylabel('y(n)');
title('second sequence');
subplot(3,1,3);
stem(convolution);
xlabel('discrete time');
ylabel('convolution(n)');
title('convolution of two sequences');

Output:
D. Write a MATLAB program to compute the cross correlation
between signals and Sequences. x=cos(2*pi*10*t), y=cos(2*pi*15*t)
by increasing the amplitude of the signal by 3 times.
Solution:
Matlab Code:
t=0:0.001:1;
x=3*cos(2*pi*10*t);
y=3*cos(2*pi*15*t);
a=xcorr(x,y);
subplot(3,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('1st signal');
subplot(3,1,2);
plot(t,y,'r');
xlabel('time');
ylabel('amplitude');
title('2nd signal');
subplot(3,1,3);
plot(a,'r');
xlabel('time');
ylabel('amplitude');
title('cross correlation signal');
Output:

E. Write a MATLAB program to verify the time invariance property of


the following sequence x1= sin(2*pi*1*n); x2= sin(2*pi*2*n), and
check whether it satisfies the time invariance property or not.
Solution:
Matlab Code:
n=0:1:5;
x1= sind(2*pi*1*n);
x2= sind(2*pi*2*n);
y=conv(x1,x2);
disp('enter a positive number for delay ');
d=input('Desired delay of the signal is ');
xd=[zeros(1,d),x1];
nxd=0:length(xd)-1;
yd=conv(xd,x2);
nyd=0:length(yd)-1;
disp('Original input signal x(n) is ');
disp(x1);
disp('Delayed input signal xd(n) is ');
disp(xd);
disp('Original output signal y(n) is ');
disp(y);
disp('Delayed output signal yd(n) is ');
disp(yd);
xp=[x1,zeros(1,d)];
subplot(2,1,1);
stem(nxd,xp);
grid on;
xlabel('Time index n');
ylabel('x(n)');
title('Original input signal x(n)');
subplot(2,1,2);
stem(nxd,xd);
grid on;
xlabel('Time index n');
ylabel('xd(n)');
title('Delayed input signal xd(n)');
yp=[y zeros(1,d)];
figure;
subplot(2,1,1);
stem(nyd,yp);
grid on;
xlabel('Time index n');
ylabel('y(n)');
title('Original output signal y(n)');
subplot(2,1,2);
stem(nyd,yd);
grid on;
xlabel('Time index n');
ylabel('yd(n)');
title('Delayed output signal yd(n)');

Output:
This system is time-invariant, since the output signals of the system are just time-
shifted versions of each other's, when the input are time-shifted versions of each
other.

F. Calculate resonance frequency and plot the response curves for


Impedance, reactance and current for series and parallel RLC circuit.
Solution:
Matlab Code:
G. Consider the mechanical system depicted in the figure. The input is
given by f(t), and the output is given by y(t). Determine the
differential equation governing the system and using MATLAB, write a
m-file and plot the system response such that forcing function f(t)=1.
Let m=10, k=1 and b=0.5. Show that the peak amplitude of the output
is about 1.8.

Solution:
Given,
input force f(t) = 1
The differential equations of the system is,
my"(t) + by'(t) + ky(t) = f(t)
=> my"(t) + by'(t) + ky(t) = 1 .......................(1) [As f(t) = 1]
Eq.(1) will be used to determine the system response y(t) in MATLAB.

Matlab Code:
m = 10;
b = 0.5;
k = 1;
syms t y(t)
y1(t) = diff(y,t);
ode = m*diff(y1,t) + b*y1(t) + k*y(t) == 1;
c1 = y(0) == 0;
c2 = y1(0) == 0;
y(t) = dsolve(ode,c1,c2);
t = 0:0.1:200;
digits(5);
y1 = double(vpa(y(t)));
plot(t,y1,'b');grid on;
xlabel('time ->');
ylabel('amplitude ->');
title('System response y(t)');
y_max = max(y1);
disp("Peak Amplitude = "+y_max);

Output:
So, the peak amplitude of the output is 1.7794 which is about to 1.8 [Showed]

H. A system has a transfer function 𝑋(𝑠) /𝑅(𝑠) =(


(15/𝑧)(𝑠+𝑧))/(𝑠^2+3𝑠+15.Plot the response of the system when R(s) is
a unit impulse and unit step for the parameter z=3, 6 and 12
Solution:
Matlab Code:
% for z=3
z=3;
num = [15/z 15] ;
den = [1 3 15] ;
sys = tf (num, den);
subplot(2,1,1)
step (sys)
subplot(2,1,2)
impulse (sys)
figure;
% for z=6
z=6;
num = [15/z 15] ;
den = [1 3 15] ;
sys = tf (num, den);
subplot(2,1,1)
step (sys)
subplot(2,1,2)
impulse (sys)
figure;
% for z=12
z=612;
num = [15/z 15] ;
den = [1 3 15] ;
sys = tf (num, den);
subplot(2,1,1)
step (sys)
subplot(2,1,2)
impulse (sys)
figure;

Output:
For z=3,
For z=6,

For z=12,

You might also like