Premier University: Dept. of CSE Lab Report
Premier University: Dept. of CSE Lab Report
Dept. of CSE
Lab Report
SUBMITTED BY
2. Experiment name:
Familiarization with MATLAB
and Functions in MATLAB.
3. Objectives: To be familiar
with MATLAB.
6. Code: Script-
a= 1;
b = 5;
addition = a+b;
Script-
c=[1 2; 3 4]
c=
1 2
3 4
>> d= inv(c);
>> d d =
-2.0000 1.0000
1.5000 -0.5000
7. Figure:
2
Figure:01
Figure:02
9. Discussion:
It was the first day we were using MATLAB software. Firstly, we took two variables a and b than adder them
and executed the them. And for the second problem we took a variable and assigned a square matrix. Then used
inverse function. We are now able to use the MATLAB software properly.
3
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
1. Experiment no: 01
2. Experiment name:
Observation of Matrix
operations in MATLAB
3. Objectives: To perform matrix
additions, subtractions and
multiplications in MATLAB.
6. Code:
a= [1 2 3; 2 3 4; 3 4 5]
b= [5 4 3; 4 3 2; 3 2 1]
Add= a+b;
Sub= a-b;
Mul= a*b;
7. Figure:
Figure:01
9. Discussion:
Here, we are executing the addition, subtraction and multiplication function. These are some normal arithmetic
functions. In MATLAB we can process all the matrix functions properly.
5
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
6. Code:
1. Plot the following function y(x) = x^2 , -2 ≥ 0 ≥ 2 x =
-2 : 0.01 : 2; y = x .^ 2; plot(x,y);
2. Plot the y(x) = x^2 cos(x), g(x) = xcos (x) and f(x) =
2^xsin (x), 0 ≤ x ≤ 2π in the same figure x = 0 :
pi/100 : 2*pi; subplot(1, 3, 1); y = (x.^2) .* cos(x);
plot(x,y); subplot(1, 3, 2); g = x .* cos(x); plot(x,g,'r');
subplot(1, 3, 3); f = 2.^(x .* sin(x)); plot(x,f,'--');
Figure:01
7
Figure:2
Figure:3
9. Discussion:
Here, three problems are given where we are learning to use plot and subplot making concept using MATLAB
software. In the first program we are implementing a plot with the given range and equation. To solve the second
problem, we have to use 3 subplots here to do the three different equations with the same range. In the last problem we
had to find out a simple plot. We are able to solve these problems properly using MATLAB software.
8
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
5.Code:
1.
t= -10:0.1:10;
unitstep1=t>=0;
unitstep2=t>=6;
x=unitstep1-
unitstep2; plot(t,x)
ylim([-1.5 1.5]) hold
on
2.
T=2*(1/50); fs=1000;
t=0:1/fs:T-1/fs;
x=10*sawtooth(2.*pi*50*t,1/2)
; plot(t,x) hold on
3.
f=50;
OverSampleRate=100;
fs=OverSampleRate.*f
; d1=60; d2=40;
nCycle=2;
t=0:1/fs:nCycle*(1/f);
y1=10.*square(2.*pi.*f.*t,d1);
y2=15.*square(2.*pi.*f.*t,d2);
10
plot(t,y1,'Green','LineWidth',2)
; hold on
plot(t,y2,'red','LineWidth',2);
axis([0 0.1 -15 15]) grid on
4.
5.
t=-20:0.1:20
unitstep=t>=0;
impulse=t==0;
ramp=t.*unitstep;
plot(t,unitstep,'green')
hold on
plot(t,impulse,'blue')
hold on
plot(t,ramp,'black')
7. Figure:
11
Figure:01
Figure:2
Figure:3
12
Figure:4
Figure:5
9. Discussion:
In this experiment, five problems are given where we are learning to use sawtooth, ramp and impulse using
concept using MATLAB software. Firstly, we learn the use of ylim. After that, we use the sawtooth function. Then we
use ramp and impulse function. At last, we make the plot form the given equation. For the first problem we found
square shaped signal. In the second program we found a pyramid shaped signal. In the 3 rd plot a rectangle shaped
signal. And 4th and 5th plot are accordingly sin shaped and a unique signal.
13
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
3. Objectives: To perform
differential operation in
MATLAB.
Code:
1.
syms a t; a = 2; y = exp(-a.*t);
y1 = matlabFunction(diff(y));
y2 =
matlabFunction(diff(y,2)); y3
= matlabFunction(diff(y,3)); t
= linspace(0,4*pi,400); a1 =
y1(t); a2 = y2(t); a3 = y3(t);
plot(t,a1,'r',t,a2,'g',t,a3,'b');
2. syms a w t; a = 2; w = 660; y =
exp(-a.*t).*sin(w.*t); y1 =
matlabFunction(diff(y)); y2 =
matlabFunction(diff(y,2)); y3
= matlabFunction(diff(y,3)); t
= linspace(0,6*pi,400); a1 =
y1(t); a2 = y2(t); a3 = y3(t);
plot(t,a1,'b',t,a2,'g',t,a3,'r');
3. syms a w t; a = 2; w = 660; y =
exp(-a.*t).*cos(w.*t); y1 =
matlabFunction(diff(y)); y2 =
matlabFunction(diff(y,2)); y3
= matlabFunction(diff(y,3)); t
= linspace(0,6*pi,400); a1 =
y1(t); a2 = y2(t); a3 = y3(t);
plot(t,a1,'b',t,a2,'g',t,a3,'r');
4. syms w t; w = 60; y =
cos(w.*t);
y1 = matlabFunction(diff(y)); y2
= matlabFunction(diff(y,2)); y3
= matlabFunction(diff(y,3));
t =
0:0.1:6*pi; a1
= y1(t); a2 =
y2(t); a3 =
y3(t);
15
plot(t,a1,'g',t,a2,'r',t,a3,'b');
5. syms w t; w = 60; y =
sin(w.*t); y1 =
matlabFunction(diff(y)); y2 =
matlabFunction(diff(y,2)); y3
= matlabFunction(diff(y,3));
t =
0:0.1:6*pi; a1
= y1(t); a2 =
y2(t); a3 =
y3(t);
plot(t,a1,'g',t,a2,'r',t,a3,'b');
6. syms w t; w = 60; y =
cos(w.*t).*sin(w.*t); y1 =
matlabFunction(diff(y)); y2 =
matlabFunction(diff(y,2)); y3
= matlabFunction(diff(y,3));
t = 0:0.1:6*pi;
a1 = y1(t); a2
= y2(t); a3 =
y3(t);
plot(t,a1,'black',t,a2,'r',t,a3,'b');
7. Figure:
Figure:01
16
Figure:2
Figure:3
Figure:4
17
Figure:5
Figure:6
9. Discussion:
Here, six problems are given where we are learning different equation solving concept using MATLAB
software. In the experiment we are finding 1 st, 2nd and 3rd derivatives of given equations in MATLAB. To do that we
are trying to solve these problems that we are instructed before. In MATLAB, a variable type is the symbolic variable.
A symbolic variable is defined by the command sym and syms. The use of symbolic variables allows the computation
of limits, integrals, derivatives etc. We are able to solve these problems properly using MATLAB software.
18
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
1.
(ii) syms a t w; a = 2; w = 60; y =
exp(-a.*t).*sin(w.*t); y1 =
matlabFunction(int(y)); t =
linspace(0,4*pi,400); a1 =
y1(t); plot(t,a1,'r');
(vi) syms t w;
w = 60; y=
cos(w.*t).*sin(w.*t); y1 =
matlabFunction(int(y));
t = -5:0.05:5; a1
= y1(t);
plot(t,a1,'black')
; grid on;
2.
0:0.01:pi; a1 = y1(t);
plot(t,a1,'black'); grid on
(vii) syms t;
y = t.^2;
y1 = matlabFunction(int(y));
t = -10:0.01:10; a1 = y1(t);
plot(t,a1,'black');
grid on;
21
Figure:- 1(i)
Figure:- 1(ii)
22
Figure:- 1(iii)
Figure:- 1(iv)
23
Figure:- 1(v)
Figure:- 1(vi)
24
Figure:- 1(vii)
Figure:- 2(i)
25
Figure:- 2(ii)
Figure:- 2(iii)
26
Figure:- 2(iv)
Figure:- 2(v)
27
Figure:- 2(vi)
Figure:- 2(vii)
Discussion:
Here, we are solving integral problem using MATLAB software in this experiment. To solve these problems, we are
given here some equation. We used int(expr, var) to compute the indefinite integral of expr with respect to the
symbolic scalar variablevar and int(expr,var,a,b) to compute the definite integral of expr with respect to var from a to
If we do not specify it, int uses the default variable determined by symvar. If expr is a constant, then the default
variable is x. We used some other syntax like int(___, Name, Value) and others to solve those integral problem. At last
we found the plot given above in the report.
28
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
Section: B2
Experiment no: 07
Experiment name: Evaluation of convolution integral in MATLAB.
Objectives: To perform convolution of continuous time signals.
Software: MATLAB 2016.
Code:
th = 0:0.01:1; tx =
0:0.01:2; h = 1-th;
a = ones(size(tx));
b = conv(x,h);
plot(b);
Figure:
Figure: 01
Discussion:
Here in the experiment we are trying to to perform convolution of continuous time signals.o perform convolution of
continuous time signals. To do this we write a code given above in the report. The impulse response of a linear
timeinvariant system completely specifies the system. More specifically,if the impulse response of a system is known
one can compute the system output for any input signal. We now present on of most important topics in signals and
systems theory. We managed to found a signal plot at last.
30
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
2.
a=input('Width of pulse"');
t=input('Range of pulse:');
s=rectpuls(t,a);
subplot(2,1,1) plot(t,s)
axis([-2 2 0 2 ]) S=fft(s);
subplot(2,1,2)
plot(t,fftshift(abs(S)
3.
Figure:
Figure:1
Figure:2
33
Figure:3
Discussion:
In the experiment we are trying to understand and implement the Fourier transform using MATLAB. To do this, we
are given three problems. Here, we used fourier(f,trans_var,eval_point) to compute the Fourier transform of f with
respect to the transformation variable trans_var at the point eval_point.f is used for Symbolic expression, symbolic
function, or vector or matrix of symbolic expressions or functions. Now we are able to do the fourier transformation
using MATLAB.
34
Premier University
Dept. of CSE
Lab Report
SUBMITTED BY
Section: B2
Experiment No: 09
Experiment Name: Implementing Laplace transform in MATLAB
Objective: To implementing Laplace transform using MATLAB Software:
MATLAB 2016.
Code:
1
syms a t
a=2
f=exp(-a.*t)
c=laplace(f,t)
syms a t omega
a=2
omega=40 f=exp(-
a.*t).*sin(omega.*t) c=laplace(f,t)
syms t omega
omega=30
f=cos(omega.*t)
c=laplace(f,t)
syms t h b
h=2 b=6
f=sin(h.*b.*t)
c=laplace(f,t)
syms t h b
36
h=2 b=6
f=cos(h.*b.*t)
c=laplace(f,t)
syms t f=t.^2
c=laplace(f,t)
syms stp t
stp=heaviside(t)
c=laplace(stp)
Result Screenshot:
2
37
4
38
6
39
7
40
Discussion:
In this experiment we are approaching to implementing Laplace transform using MATLAB. Here, we used laplace(f,
trans_var, eval_point) to compute the Laplace transform of f with respect to the transformation variable trans_var at
the point eval point. f is used Symbolic expression, symbolic function, or vector or matrix of symbolic expressions or
functions. Trans_var is used as Symbolic variable representing the transformation variable. This variable is often
called the “time variable”. Eval_point is usually used for Symbolic variable or expression representing the evaluation
point. Using these functions, we are now able to solve these problems.
41
Premier University
Dept. of CSE
42
Lab Report
Remarks
SUBMITTED BY
Name: Md. Shahiduzzaman Bhuiyan
Id: 1803510201685
Department: CSE
Year: 2021
Semester: 4th
Section: B2
Experiment No: 10
Experiment Name: Implementing z- transform in MATLAB
Objective: To implementing z- transform using MATLAB
Software: MATLAB 2016b
Code
1
syms j omega t
f=exp(j.*omega.*t)
c=ztrans(f,t)
2
43
syms h b t
f=sin(h.*b.*t)
c=ztrans(f,t)
3
syms h b t
f=cos(h.*b.*t)
c=ztrans(f,t)
4 syms
omega t
f=sin(omega.
*t)
c=ztrans(f,t)
5 syms
omega t
f=cos(omega.
*t)
c=ztrans(f,t)
6 syms
t f=t
c=ztrans(f,t)
7 syms
t f=t.^2
c=ztrans(f,t)
8 syms stp t
stp=heaviside
(t)
c=ztrans(stp)
Result Screenshot:
1
44
3
45
5
46
6
47
8
48
Discussion:
In the experiment, we are approaching to implementing z- transform using MATLAB. In order to do this, we
are performing some tasks written in the codes of the report. We are using some functions like ztrans(f, trans_index ,
eval_point) to compute the Z-transform of f with respect to the transformation index trans_index at the point
eval_point. trans_index is used for Symbolic variable representing the transformation index. This variable is often
called the “discrete time variable". eval_point is used as Symbolic variable or expression representing the evaluation
point. We written the syntax properly and found the output of the equations given in the experiment.