SlideShare a Scribd company logo
MATLAB/Simulink
Free Course to beginners
by
Mohd Esa
1Mohd Esa
2Mohd Esa
3Mohd Esa
Contents
1. Introduction
2. Basic Plotting
3. Matrices In MATLAB
4. M-File Programming
5. Control Systems
6. Digital Signal Processing
7. Modelling and control of DC Motor
8. Modelling and simulation of DC-DC converter (Buck Converter)
9. Simulation of DC-AC Converter(Voltage Source inverter)
10. Mathematical Modelling Using SimScape(Electrical Systems)
11. Laplace and Inverse Laplace Transformations using MATLAB
12. Fourier and Inverse Fourier Transformations Using MATLAB
13. Digital electronics Circuits
14. Filters using various Windows
15. Step Responses of P,I,D,PI,PD,PID Controllers
4Mohd Esa
1.Introduction
• The name MATLAB stands for MATrix
LABoratory.MATLAB is a high-performance language
for technical computing.
• It integrates computation, visualization, and
programming environment. Furthermore, MATLAB is
a modern programming language environment: it has
sophisticated data structures, contains built-in
editing and debugging tools, and supports object-
oriented programming.
• These factor make MATLAB an excellent tool for
teaching and research.
5Mohd Esa
Starting MATLAB
When you start MATLAB, a special window called the
MATLAB desktop appears. The desktop is a window
that contains other windows. The major tools within or
accessible from the desktop are:
• The Command Window
• The Command History
• The Workspace
• The Current Directory
• The Help Browser
• The Start button
6Mohd Esa
7
Using MATLAB as a calculator
• As an example of a simple interactive calculation, just type the expression
you want to evaluate. Let’s start at the very beginning. For example, let’s
suppose you want to calculate the expression, 1 + 2 × 3. You type it at the
prompt command (>>) as follows,
>> 1+2*3
ans =7
• You will have noticed that if you do not specify an output variable,
MATLAB uses a default variable ans, short for answer, to store the results
of the current calculation. Note that the variable ans is created (or
overwritten, if it is already existed). To avoid this, you may assign a value
to a variable or output argument name. For example,
>> x = 1+2*3
x =7
• will result in x being given the value 1 + 2 × 3 = 7. This variable name can
always be used to refer to the results of the previous computations.
Therefore, computing 4x will result in
>> 4*x
ans = 28.0000
8Mohd Esa
Basic arithmetic operators
9Mohd Esa
Example
The value of the expression y = 𝑒−𝑎
sin(x) + 10√y, for a = 5, x = 2, and y = 8 is computed
by
>> a = 5; x = 2; y = 8;
>> y = exp(-a)*sin(x)+10*sqrt(y)
y =28.2904
The subsequent examples are
>> log(142)
ans = 4.9558
>> log10(142)
ans = 2.1523
Note the difference between the natural logarithm log(x) and the decimal logarithm
(base 10) log10(x).
To calculate sin(π/4) and 𝑒10
, we enter the following commands in MATLAB,
>> sin(pi/4)
ans = 0.7071
>> exp(10)
ans =2.2026e+004
10Mohd Esa
Quitting MATLAB
• To end your MATLAB session, type quit in the
Command Window,
(or)
select File −→ Exit
MATLAB in the desktop main menu.
11Mohd Esa
2.Basic plotting
• MATLAB has an excellent set of graphic tools. Plotting a
given data set or the results of computation is possible
with very few commands. You are highly encouraged to
plot mathematical functions and results of analysis as
often as possible.
• Trying to understand mathematical equations with
graphics is an enjoyable and very efficient way of
learning mathematics.
• Being able to plot mathematical functions and data
freely is the most important step, and this section is
written to assist you to do just that.
12Mohd Esa
Plotting Example-1
The MATLAB command to plot a graph is plot (x,y). The vectors x = (1, 2, 3, 4, 5, 6) and y = (3, −1,
2, 4, 5, 1) produce the picture shown
>> x = [1 2 3 4 5 6];
>> y = [3 -1 2 4 5 1];
>> plot(x,y)
13Mohd Esa
Plotting Example-2
• For example, to plot the function sin (x) on the
interval *0, 2π+, we first create a vector of x values
ranging from 0 to 2π, then compute the sine of these
values, and finally plot the result
>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x , y)
– starts at 0,
– takes steps (or increments) of π/100,
– stops when 2π is reached.
14Mohd Esa
Adding titles, axis labels, and
annotations
>> xlabel(’x = 0:2pi’)
>> ylabel(’Sine of x’)
>> title(’Plot of the Sine function’)
15Mohd Esa
Multiple data sets in one plot
• Multiple (x, y) pairs arguments create multiple graphs with a single call to plot. For
example, these statements plot three related functions of x: y1 = 2 cos(x), y2 =
cos(x), and y3 = 0.5 ∗ cos(x), in the interval 0 ≤ x ≤ 2π.
>> x = 0:pi/100:2*pi;
>> y1 = 2*cos(x);
>> y2 = cos(x);
>> y3 = 0.5*cos(x);
>> plot(x,y1,’--’,x,y2,’-’,x,y3,’:’)
>> xlabel(’0 leq x leq 2pi’)
>> ylabel(’Cosine functions’)
>> legend(’2*cos(x)’,’cos(x)’,’0.5*cos(x)’)
>> title(’Typical example of multiple plots’)
>> axis([0 2*pi -3 3])
16Mohd Esa
17
Specifying line styles and colors
• It is possible to specify line styles, colors, and markers (e.g., circles, plus signs, . . . )
using the plot command:
plot(x,y,’style_color_marker’)
where style_color_marker is a triplet of values from below table
18Mohd Esa
3.Matrices in Matlab
• The purpose of this section is to show how to
create vectors and matrices in MATLAB.An
array of dimension 1 ×n is called a row vector,
whereas an array of dimension m × 1 is called
a column vector. The elements of vectors in
MATLAB are enclosed by square brackets and
are separated by spaces or by commas.
19Mohd Esa
Row & Column Vector
To enter a row vector, v, type
>> v = [1 4 7 10 13]
v = 1 4 7 10 13
Column vectors are created in a similar way, however, semicolon
(;) must separate the components of a column vector,
>> w = [1;4;7;10;13]
w =
1
4
7
10
13 20Mohd Esa
Converting Row Vector into Column
Vector
• A row vector is converted to a column vector using the
transpose operator. The transpose operation is
denoted by an apostrophe or a single quote (’).
• >> w = v’
w =
1
4
7
10
13
21Mohd Esa
Entering a matrix
• A matrix is an array of numbers. To type a
matrix into MATLAB you must
• begin with a square bracket, [
• separate elements in a row with spaces or
commas (,)
• use a semicolon (;) to separate rows
• end the matrix with another square bracket, ]
22Mohd Esa
Example
• Here is a typical example. To enter a matrix A,
such as,
>> A = [1 2 3; 4 5 6; 7 8 9]
• MATLAB then displays the 3 × 3 matrix as follows,
A =
1 2 3
4 5 6
7 8 9
23Mohd Esa
Correction Through Indexing
• Correcting any entry is easy through indexing.
Here we substitute A(3,3)=9 by
A(3,3)=0. The result is
>> A(3,3) = 0
A =
1 2 3
4 5 6
7 8 0
24Mohd Esa
Determining Dimensions of a Matrix
• To determine the dimensions of a matrix or
vector, use the command size. For example,
• >> size(A)
ans =
3 3
means 3 rows and 3 columns
25Mohd Esa
Transposing a matrix
• The transpose operation is denoted by an
apostrophe or a single quote (’). It flips a matrix
• about its main diagonal and it turns a row vector
into a column vector. Thus,
>> A’
ans =
1 4 7
2 5 8
3 6 0
26Mohd Esa
Matrix Athematic
>> C = A.*B
C =
10 40 90
160 250 360
490 640 810
>> A.^2
ans =
1 4 9
16 25 36
49 64 81
27Mohd Esa
Matrix inverse
• >> A = [1 2 3; 4 5 6; 7 8 0];
>> inv(A)
ans =
-1.7778 0.8889 -0.1111
1.5556 -0.7778 0.2222
-0.1111 0.2222 -0.1111
>> det(A)
ans =
27
28Mohd Esa
Matrix Functions
29Mohd Esa
4.M-Files in MATLAB
• A script file is an external file that contains a
sequence of MATLAB statements. Script files
have a filename extension .m and are often
called M-files. M-files can be scripts that
simply execute a series of MATLAB
statements, or they can be functions that can
accept arguments and can produce one or
more outputs.
30Mohd Esa
Example-1 of M-File
• Use the MATLAB editor to create a file: File →
New → M-file.
A = [1 2 3; 3 3 4; 2 3 3];
b = [1; 1; 2];
x = Ab
Save the file, for example, example1.m.
• Run the file, in the command line, by typing:
>> example1
x =
-0.5000
1.5000
-0.5000
31Mohd Esa
Example-2 of M-File(Same example previously
executed in command window)
Plot the following cosine functions, y1 = 2 cos(x), y2 = cos(x), and y3 = 0.5 ∗
cos(x), in the interval 0 ≤ x ≤ 2π.
• Create a file, say example2.m, which contains the following commands
x = 0:pi/100:2*pi;
y1 = 2*cos(x);
y2 = cos(x);
y3 = 0.5*cos(x);
plot(x,y1,’--’,x,y2,’-’,x,y3,’:’)
xlabel(’0 leq x leq 2pi’)
ylabel(’Cosine functions’)
legend(’2*cos(x)’,’cos(x)’,’0.5*cos(x)’)
title(’Typical example of multiple plots’)
axis([0 2*pi -3 3])
Run the file by typing example2 in the Command Window.
32Mohd Esa
Program to compute area of circle
To print results in a MATLAB function we use the the fprintf
statement. The syntax is very similar to the corresponding C
command. The function input allows the user to provide input
data from the keyboard. A simple example is below.
Function area circle
% interactive program to compute area of circle
r = input(’Give radius of circle : ’);
a = pi*rˆ2;
fprintf(’The area of circle with radius %.2f is %.6f n’, r, a);
33Mohd Esa
5.Control Systems
TRANSFER FUNCTION FROM ZEROS AND POLES
MATLAB PROGRAM:
z=input(‘enter zeroes’)
p=input(‘enter poles’)
k=input(‘enter gain’)
[num,den]=zp2tf(z,p,k)
tf(num,den)
EXAMPLE:
Given poles are -3.2+j7.8,-3.2-j7.8,-4.1+j5.9,-4.1-j5.9,-8 and the zeroes are -
0.8+j0.43,-0.8-j0.43,-0.6 with a gain of 0.5
34Mohd Esa
ZEROS AND POLES FROM TRANSFER
FUNCTION
MATLAB PROGRAM:
num = input(‘enter the numerator of the transfer function’)
den = input(‘enter the denominator of the transfer function’)
[z,p,k] = tf2zp(num,den)
EXAMPLE:
35Mohd Esa
STEP RESPONSE OF A TRANSFER
FUNCTION
num = input(‘enter the numerator of the transfer function’)
den = input(‘enter the denominator of the transfer function’)
step(num,den)
36Mohd Esa
IMPULSE RESPONSE OF A TRANSFER
FUNCTION
num = input(‘enter the numerator of the transfer function’)
den = input(‘enter the denominator of the transfer function’)
impulse(num,den)
37Mohd Esa
ROOT LOCUS FROM A TRANSFER FUNCTION
PROGRAM:
num=input(‘enter the numerator of the transfer function’)
den=input(‘enter the denominator of the transfer function’)
h=tf(num,den)
rlocus(h)
38Mohd Esa
BODE PLOT FROM A TRANSFER FUNCTION
PROGRAM:
num=input('enter the numerator of the transfer function')
den=input('enter the denominator of the transfer function')
h=tf(num,den)
[gm pm wcp wcg]=margin(h)
bode(h)
39Mohd Esa
TRANSFER FUNCTION FROM STATE MODEL
MATLAB PROGRAM:
A =input(‘enter the matrix A’)
B= input(‘enter the matrix B’)
C = input(‘enter the matrix C’)
D= input(‘enter the matrix D’)
Sys =ss2tf(A,B,C,D)
40Mohd Esa
STATE MODEL FROM TRANSFER FUNCTION
There are three methods for obtaining state model from transfer function:
1. Phase variable method
2. Physical variable method
3. Canonical variable method
Out of three methods given above canonical form is probably the most
straightforward method
for converting from the transfer function of a system to a state space model is to
generate a
model in "controllable canonical form.“
PROGRAM:
num=input(‘enter the numerator of the transfer function’)
den=input(‘enter the denominator of the transfer function’)
ss(tf(num,den))
41Mohd Esa
STATE MODEL FROM ZEROS AND POLES
PROGRAM:
z=input('enter zeros')
p=input('enter poles')
k=input('enter gain')
[A,B,C,D]=zp2ss(z,p,k)
42Mohd Esa
STEP RESPONSE OF A STATE MODEL
PROGRAM:
A=input(‘enter matrix A’)
B=input(‘enter matrix B’)
C=input(‘enter matrix C’)
D=input(‘enter matrix D’)
Step(A,B,C,D)
43Mohd Esa
IMPULSE REPONSE OF A STATE MODEL
PROGRAM:
A=input('enter matrix A')
B=input('enter matrix B')
C=input('enter matrix C')
D=input('enter matrix D')
impulse(A,B,C,D)
44Mohd Esa
RAMP RESPONSE OF A STATE MODEL
PROGRAM:
t=0:0.01:10;
u=t
A=input('enter matrix A')
B=input('enter matrix B')
C=input('enter matrix C')
D=input('enter matrix D')
lsim(A,B,C,D,u,t)
45Mohd Esa
NYQUIST PLOT FROM TRANSFER
FUNCTION
PROGRAM:
num=input(‘enter the numerator of the transfer function’)
den=input(‘enter the denominator of the transfer function’)
h=tf(num,den)
nyquist(h)
[gm pm wcp wcg]=margin(h)
if(wcp>wcg)
disp(‘system is stable’)
else
disp(‘system is unstable’)
end
46Mohd Esa
6.Circuit Theorems
• Superposition theorem
• Thevenins Theorem
• Norton's Theorem
47Mohd Esa
Super Position Theorem
Find Currents in each Branch
48Mohd Esa
Step-1
Take only One Emf Source 20v while short
Circuit other
49Mohd Esa
Step-1
Take only One Emf Source 28 V while short Circuit
other
50Mohd Esa
Total currents in different branches are
51Mohd Esa
Superposition Theorem Program
clc;
E1=input('enter the source voltage 1:');
E2=input('enter the source voltage 2:');
disp('first step:');
r1=input('enter resistance 1:');
r2=input('enter resistance 2:');
r3=input('enter resistance 3:');
disp('total resistance in first step is');
rftotal=(r1+((r2*r3)/(r2+r3)));
disp(rftotal)
disp('current through resistance R1:');
if1=E1/rftotal;
disp(if1)
disp('current through resistance R2:');
if2=(if1*(r3/(r3+r2)));
disp(if2)
disp('current through resistance R3:');
if3=(if1*(r2/(r3+r2)));
disp(if3)
disp('second step:');
disp('total resistance in second step is');
rstotal=(r2+((r3*r1)/(r1+r3)));
disp(rstotal)
disp('current through resistance R2:');
is2=E2/rstotal;
disp(is2)
disp('current through resistance R1:');
is1=(is2*(r3/(r3+r1)));
disp(is1)
disp('current through resistance R3:');
is3=(is2*(r1/(r1+r3)));
disp(is3)
disp('The total currents in different branches are:');
disp('current through resistance R1:');
i1=if1-is1;
disp(i1)
disp('current through resistance R2:');
i2=is2-if2;
disp(i2)
disp('current through resistance R3:');
i3=if3+is3;
disp(i3)
52Mohd Esa
Program Result
enter the source voltage 1:20
enter the source voltage 2:28
first step:
enter resistance 1:8
enter resistance 2:10
enter resistance 3:12
total resistance in first step is
13.4545
current through resistance R1:
1.4865
current through resistance R2:
0.8108
current through resistance R3:
0.6757
second step:
total resistance in second step is
14.8000
current through resistance R2:
1.8919
current through resistance R1:
1.1351
current through resistance R3:
0.7568
The total currents in different branches are:
current through resistance R1:
0.3514
current through resistance R2:
1.0811
current through resistance R3:
1.4324
53Mohd Esa
Thevenins Theorem
54Mohd Esa
Cont…
55
(iii) il=(Eth/(rth+rload))=36/6+30=1A
Mohd Esa
Thevenins Theorem Program
E1=input('enter the source voltage:');
r1=input('enter resistance r1:');
r2=input('enter resistance r2:');
rload=input('enter the load
resistance:');
r=input('enter resistance of voltage
source:');
disp('Equivalent emf of the
network:');
disp('current in the network before
load resistance is connected');
i=(E1/(r1+r2+r));
disp(i)
disp('voltage across terminals LM:');
Eth=i*r2;
disp(Eth)
disp('Equivalent resistance of the
network:');
rth=((r2*(r1+r))/(r2+(r1+r)));
disp(rth)
disp('current in load resistance:');
il=(Eth/(rth+rload));
disp(il)
56Mohd Esa
Program Result
57Mohd Esa
Nortons Theorem
58Mohd Esa
Nortons Theorem Program
E1=input('enter the source voltage:');
r1=input('enter resistance r1:');
r2=input('enter resistance r2:');
r3=input('enter resistance r3:');
r4=input('enter resistance r4:');
disp('short circuit current is:');
In=E1/r1;
disp(In)
disp('Nortans Resistance Rn is:');
Rn=((r1*(r3+r4))/(r1+r3+r4));
disp(Rn)
disp('current through resistance r2 is:');
i=(In*(Rn/(Rn+r2)));
disp(i)
59Mohd Esa
Program Result
60Mohd Esa
7.Digital Signal Processing
• Representation of Basic Signals
• Fast Fourier Transform
• Inverse Fast Fourier Transform
61Mohd Esa
Representation of basic signals
%Unit Impulse Signal%
n1=input('Enter the no of
samples');
x1=[-n1:1:n1];
y1=[zeros(1,n1),ones(1,1),zero
s(1,n1)];
subplot(2,3,1);
stem(x1,y1);
xlabel('Time Period');
ylabel('Amplitude');
title('Unit Impulse Signal');
%Unit Step Signal%
n2=input('Enter the no of
samples');
x2=[0:1:n2];
y2=ones(1,n2+1);
subplot(2,3,2);
stem(x2,y2);
xlabel('Time Period');
ylabel('Amplitude');
title('Unit Step Signal');
%Unit Ramp Signal%
n3=input('Enter the no of
samples');
x3=[0:1:n3];
subplot(2,3,3);
stem(x3,x3);
xlabel('Time Period');
ylabel('Amplitude');
title('Unit Ramp Signal');
%Exponential Signal%
n4=input('Enter the length of
the signal');
a=input('Enter the value of
a:');
x4=[0:1:n4];
y4=a*exp(x4);
subplot(2,3,4);
stem(x4,y4);
xlabel('Time Period');
ylabel('Amplitude');
title('Exponential Signal');
%Sinusoidal Signal%
x5=[-pi:0.1:pi];
y5=sin(2*pi*x5);
subplot(2,3,5);
plot(x5,y5);
xlabel('Time Period');
ylabel('Amplitude');
title('Sinusoidal Signal');
%Cosine Signal%
x6=[-pi:0.1:pi];
y6=cos(2*pi*x5);
subplot(2,3,6);
plot(x6,y6);
xlabel('Time Period');
ylabel('Amplitude');
title('Cosine Signal')
62Mohd Esa
Basic Signals
63Mohd Esa
Fast Fourier Transform-Program
%Fast Fourier Transform%
x=input('enter the input sequence');
n=input('enter the length of the sequence');
subplot(2,1,1);
stem(x);
xlabel('time');
ylabel('amplitude');
title(‘Input Sequence’);
y1=fft(x,n);
subplot(2,2,2);
stem(y1);
xlabel('time');
ylabel('amplitude');
title(‘Fast fourier Transform’);
64Mohd Esa
FFT Results
65Mohd Esa
Inverse Fast Fourier Transform-Program
%Inverse Fast Fourier Transform%
x=input('enter the input sequence');
n=input('enter the length of the sequence');
subplot(3,1,1);
stem(x);
xlabel('time');
ylabel('amplitude');
title(‘input sequence’);
xk=ifft(x,n);
magxk=abs(xk);
anglexk=angle(xk);
k=0:1:n-1;
subplot(3,1,2);
stem(k,magxk);
xlabel('time');
ylabel('amplitude');
title('mag plot');
subplot(3,1,3);
stem(k,anglexk);
xlabel('time');
ylabel('amplitude');
title('phase plot');
66Mohd Esa
IFFT Results
67Mohd Esa
Modelling and control of DC Motor
68Mohd Esa
System Equations
69Mohd Esa
70Mohd Esa
71Mohd Esa
Block Diagram of DC Motor
72Mohd Esa
Transfer Function
73Mohd Esa
Matlab Simulation of DC motor in
Open Loop
74Mohd Esa
Simulation Results for dc motor open
loop
75Mohd Esa
Closed loop speed control of DC Motor
using PI Controller
76Mohd Esa
Simulation Results
77Mohd Esa
8.DC-DC Converter Simulation
(Buck Converter)
78Mohd Esa
Simulation results for Buck Converter
79Mohd Esa
Simulink Parameters (Buck Converter)
Formula Calculated Value
𝛼 =
𝑉0
𝑉𝑔
𝛼 =
𝑉0
𝑉𝑔
=
5
12
=41.67%
L=
V0(1−α)Ts
∆I0
;∆I0 = 0.5A L=291.65e-6 H
C=
∆𝐼0
8∆𝑉0 𝑓𝑠
; ∆𝑉0 = 20𝑚𝑉 C=156.25e-6 F
Switching Frequency 20kHz
Load Resistance 23 Ohms
80Mohd Esa
9.DC-AC Converter Simulation
(VSI)
81Mohd Esa
Pulses generation Using SPWM
82Mohd Esa
SPWM Technique
83Mohd Esa
Line Voltage
84Mohd Esa
Phase Voltage
85Mohd Esa
THD Calculation
86Mohd Esa
THD Analysis of Line Voltage
87Mohd Esa
10.Mathematical Modelling Using SimScape
(Electrical Systems)
Simscape provides an environment for modeling
and simulating physical systems spanning
mechanical, electrical, hydraulic, and other
physical domains. It provides fundamental
building blocks from these domains that you can
assemble into models of physical components,
such as electric motors,inverting op-amps,
hydraulic valves, and ratchet mechanisms.
88Mohd Esa
Features of SimScape
• Single environment for modeling and simulating mechanical,
electrical, hydraulic, thermal, and other multidomain physical
systems
• Libraries of physical modeling blocks and mathematical elements
for developing custom components
• MATLAB based Simscape language, enabling text-based authoring
of physical modeling components, domains, and libraries
• Physical units for parameters and variables, with all unit conversions
handled automatically
• Ability to simulate models that include blocks from related physical
modeling products without purchasing those products
• Support for C-code generation
89Mohd Esa
SimScape Libraries
Simscape block library contains two libraries that belong to
the Simscape™ product:
• Foundation library — Contains basic hydraulic, pneumatic,
mechanical, electrical, magnetic, thermal, thermal liquid,
and physical signal blocks, organized into sublibraries
according to technical discipline and function performed
• Utilities library — Contains essential environment blocks for
creating Physical Networks models
• In addition, if you have installed any of the add-on products
of the Physical Modeling family, you will see the
corresponding libraries under the main Simscape library.
90Mohd Esa
Foundation Libraries
• Simscape Foundation libraries contain a
comprehensive set of basic elements and building
blocks, such as:
• Mechanical building blocks for representing one-
dimensional translational and rotational motion
• Electrical building blocks for representing
electrical components and circuits
• Magnetic building blocks that represent
electromagnetic components
91Mohd Esa
• Hydraulic building blocks that model fundamental hydraulic effects
and can be combined to create more complex hydraulic
components
• Pneumatic building blocks that model fundamental pneumatic
effects based on the ideal gas law
• Thermal building blocks that model fundamental thermal effects
• Thermal liquid building blocks that model fundamental
thermodynamic effects in liquids
• Physical Signals block library that lets you perform math operations
on physical signals, and graphically enter equations inside the
physical network
• Using the elements contained in these Foundation libraries, you can
create more complex components that span different physical
domains. You can then group this assembly of blocks into a
subsystem and parameterize it to reuse and share these
components.
92Mohd Esa
Utilities Library
• In addition to Foundation libraries, there is also a Simscape
Utilities library, which contains utility blocks, such as:
• Solver Configuration block, which contains parameters
relevant to numerical algorithms for Simscape simulations.
Each Simscape diagram (or each topologically distinct
physical network in a diagram) must contain a Solver
Configuration block.
• Simulink-PS Converter block and PS-Simulink Converter
block, to connect Simscape and Simulink® blocks. Use the
Simulink-PS Converter block to connect Simulink outports
to Physical Signal inports. Use the PS-Simulink Converter
block to connect Physical Signal outports to Simulink
inports.
93Mohd Esa
94Mohd Esa
95Mohd Esa
Electrical System Using SimScape
• In this example, you are going to model an electrical system and makes you
familiar with using the basic SimScape blocks.
96Mohd Esa
97Mohd Esa
Simulation Result
98Mohd Esa
11.Laplace and Inverse Laplace
Transformations using MATLAB
Laplace Transforms: In this example, we will compute the
Laplace transform of some commonly used functions.
99
Program Result
syms s t a b w
laplace(a)
laplace(t^2)
laplace(t^9)
laplace(exp(-b*t))
laplace(sin(w*t))
laplace(cos(w*t))
ans =
1/s^2
ans =
2/s^3
ans =
362880/s^10
ans =
1/(b + s)
ans =
w/(s^2 + w^2)
ans =
s/(s^2 + w^2)
Mohd Esa
Inverse Laplace Transform
MATLAB allows us to compute the inverse Laplace transform using the command
ilaplace.
Program Result
syms s t a b w
ilaplace(1/s^7)
ilaplace(2/(w+s))
ilaplace(s/(s^2+4))
ilaplace(w/(s^2 + w^2))
ilaplace(s/(s^2 + w^2))
ans =
t^6/720
ans =
2*exp(-t*w)
ans =
cos(2*t)
ans =
sin(t*w)
ans =
cos(t*w)
100Mohd Esa
12.Fourier and Inverse Fourier
transformations Using MATLAB
Program For Fourier Transformation
syms x
f = exp(-2*x^2); %our function
ezplot(f,[-2,2]) % plot of our function
FT = fourier(f) % Fourier transform
The following result is displayed −
FT =
(2^(1/2)*pi^(1/2)*exp(-w^2/8))/2
Plotting the Fourier transform as −
ezplot(FT)
101Mohd Esa
Inverse Fourier Transform
MATLAB provides the ifourier command for
computing the inverse Fourier transform of a
function. For example
102Mohd Esa
13.Digital Electronics Circuits
HALF ADDER
103Mohd Esa
104Mohd Esa
Full Adder
105Mohd Esa
106Mohd Esa
Half subtractor
107Mohd Esa
108Mohd Esa
Full subtractor
109Mohd Esa
110Mohd Esa
14-Filters using Various windows
• Filters
Low pass filters
High pass filters
Band pass filters
Band stop filters
• Windows
Rectangular
Hamming
Hanning
Blackman
111Mohd Esa
Low Pass Filter
Low pass filter Program:
clc;
clear all;
N=50;
wc=0.5*pi;
b=fir1(N,(wc/pi),rectwin(N+1));
w=0:.001:pi;
H=freqz(b,1,w);
plot(w,abs(H))
%replace rectwin with hamming/hanning/Blackman windows
112Mohd Esa
LPF with rectangular window
113Mohd Esa
LPF with Hamming Window
114Mohd Esa
LPF with Hanning Window
115Mohd Esa
LPF with Blackman Window
116Mohd Esa
High Pass Filter
clc;
clear all;
N=50;
wc=0.5*pi;
b=fir1(N,(wc/pi),'high',rectwin(N+1));
w=0:.001:pi;
H=freqz(b,1,w);
plot(w,abs(H))
%replace rectwin with hamming/hanning/Blackman windows
117Mohd Esa
HPF with Rectangular Window
118Mohd Esa
HPF with Hamming Window
119Mohd Esa
HPF with Hanning Window
120Mohd Esa
HPF with Blackman Window
121Mohd Esa
Band Pass Filter
clc;
clear all;
N=50;
wc1=0.5*pi;
wc2=0.6*pi;
b=fir1(N,[wc1/pi,wc2/pi],'bandpass',rectwin(N+1));
w=0:.001:pi;
H=freqz(b,1,w);
plot(w,abs(H))
%replace rectwin with hamming/hanning/Blackman windows
122Mohd Esa
BPF with rectangular Window
123Mohd Esa
BPF with Hamming Window
124Mohd Esa
BPF with Hanning Window
125Mohd Esa
BPF with Blackman Window
126Mohd Esa
Band Stop Filter
clc;
clear all;
N=50;
wc1=0.5*pi;
wc2=0.6*pi;
b=fir1(N,[wc1/pi,wc2/pi],'stop',rectwin(N+1));
w=0:.001:pi;
H=freqz(b,1,w);
plot(w,abs(H))
%replace rectwin with hamming/hanning/Blackman windows
127Mohd Esa
BSF with Rectangular Window
128Mohd Esa
BSF with Hamming Window
129Mohd Esa
BSF with Hanning Window
130Mohd Esa
BSF with Blackman Window
131Mohd Esa
Step Responses of P,I,D,PI,PD,PID
Controllers
P Controller (kp=1)
clc
clear all
close all
kp=input('enter the value of kp');
num=[1+kp];
den=[1,20,10+kp];
h=tf(num,den);
step(h)
figure
g=feedback(h,1);
step(g)
figure
step(h,g)
figure
nyquist(g)
figure
bode(g)
132Mohd Esa
133Mohd Esa
I Controller(ki=1)
clc
clear all
close all
ki=input('enter the value of ki');
num=[1+ki];
den=[1,20,10,ki];
h=tf(num,den);
step(h)
figure
g=feedback(h,1);
step(g)
figure
step(h,g)
figure
nyquist(g)
figure
bode(g) 134Mohd Esa
135Mohd Esa
D Controller(kd=1)
clc
clear all
close all
kd=input('enter the value of kd');
num=1;
den=[1,(20+kd),10];
h=tf(num,den);
step(h)
figure
g=feedback(h,1);
step(g)
figure
step(h,g)
figure
nyquist(g)
figure
bode(g) 136Mohd Esa
137Mohd Esa
PD Controller (kp=1;kd=2)
clc
clear all
close all
kd=input('enter the value of kd');
kp=input('enter the value of kp');
num=1+kp;
den=[1,20+kd,10+kp];
h=tf(num,den);
step(h)
figure
g=feedback(h,1);
step(g)
figure
step(h,g)
figure
nyquist(g)
figure
bode(g)
138Mohd Esa
139Mohd Esa
PI Controller(kp=1,ki=2)
clc
clear all
close all
kp=input('enter the value of kp');
ki=input('enter the value of ki');
num=[kp,ki];
den=[1,20,10+kp,ki];
h=tf(num,den);
step(h)
figure
g=feedback(h,1);
step(g)
figure
step(h,g)
figure
nyquist(g)
figure
bode(g)
140Mohd Esa
141Mohd Esa
PID Controller (kp=1;ki=2;kd=3)
clc
clear all
close all
kp=input('enter the value of kp');
ki=input('enter the value of ki');
kd=input('enter the value of kd');
num=[1+ki];
den=[1+kd,20+kp,10+ki];
h=tf(num,den);
step(h)
figure
g=feedback(h,1);
step(g)
figure
step(h,g)
figure
nyquist(g)
figure
bode(g)
142Mohd Esa
143Mohd Esa
144
Follow Mohd Esa on:
Mail:zmohdesa@gmail.com
Mohd Esa
145Mohd Esa

More Related Content

PPTX
Signal flow graph
PDF
Matlab for beginners, Introduction, signal processing
PPTX
Seminar on MATLAB
PDF
MATLAB INTRODUCTION
PDF
Introduction to matlab
PPTX
Introduction to MATLAB
PDF
Introduction to Matlab
PPTX
Matlab Introduction
Signal flow graph
Matlab for beginners, Introduction, signal processing
Seminar on MATLAB
MATLAB INTRODUCTION
Introduction to matlab
Introduction to MATLAB
Introduction to Matlab
Matlab Introduction

What's hot (20)

PDF
Introduction to simulink (1)
PPTX
Introduction to matlab lecture 1 of 4
PDF
Basics of matlab
PPT
Matlab Overviiew
PPTX
Matlab for Electrical Engineers
PPTX
Z bus building algorithm
PDF
control engineering revision
PPT
Introduction to matlab
PDF
MATLAB Basics-Part1
PPT
Simulink Presentation.ppt
PPTX
An Introduction to MATLAB for beginners
PPTX
EC8352-Signals and Systems - Laplace transform
PPTX
Matlab ppt
PPTX
Matlab ppt
PPTX
power flow and optimal power flow
PPTX
Chapter 2: Fundamentals of Electric Circuit
PPTX
Matlab Functions
PDF
Smith chart basics
PDF
Part 1:Electrostatics
PDF
Lecture 5: The Convolution Sum
Introduction to simulink (1)
Introduction to matlab lecture 1 of 4
Basics of matlab
Matlab Overviiew
Matlab for Electrical Engineers
Z bus building algorithm
control engineering revision
Introduction to matlab
MATLAB Basics-Part1
Simulink Presentation.ppt
An Introduction to MATLAB for beginners
EC8352-Signals and Systems - Laplace transform
Matlab ppt
Matlab ppt
power flow and optimal power flow
Chapter 2: Fundamentals of Electric Circuit
Matlab Functions
Smith chart basics
Part 1:Electrostatics
Lecture 5: The Convolution Sum
Ad

Similar to Matlab-free course by Mohd Esa (20)

PPT
Introduction to Matlab - Basic Functions
PPTX
Introduction to MATLAB Programming for Engineers
PDF
A complete introduction on matlab and matlab's projects
PPTX
Mat lab day 1
PPTX
1. Introduction.pptx
PPT
Matlab introduction
DOCX
Introduction to matlab
PPTX
matlab presentation fro engninering students
PPT
MatlabIntro (1).ppt
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
PDF
An Introduction to MATLAB with Worked Examples
PPTX
1. Introduction to Computing - MATLAB.pptx
PPT
MATLAB-Introd.ppt
PPTX
01 Chapter MATLAB introduction
PPTX
Basic MATLAB-Presentation.pptx
PPT
Matlab anilkumar
PPTX
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
PPT
Palm m3 chapter1b
PDF
Introduction to matlab
PDF
Introduction to matlab
Introduction to Matlab - Basic Functions
Introduction to MATLAB Programming for Engineers
A complete introduction on matlab and matlab's projects
Mat lab day 1
1. Introduction.pptx
Matlab introduction
Introduction to matlab
matlab presentation fro engninering students
MatlabIntro (1).ppt
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
An Introduction to MATLAB with Worked Examples
1. Introduction to Computing - MATLAB.pptx
MATLAB-Introd.ppt
01 Chapter MATLAB introduction
Basic MATLAB-Presentation.pptx
Matlab anilkumar
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
Palm m3 chapter1b
Introduction to matlab
Introduction to matlab
Ad

More from Mohd Esa (13)

PDF
The Science of Success-Coursera certificate 3
PDF
Coursera certificate 2
PDF
Coursera certificate 1
PDF
Multilevel Inverter and Multipliers
PDF
Design and Verification of 4 X 4 Wallace Tree Multiplier
PDF
RTL Verification and FPGA Implementation of 4x4 Vedic Multiplier
PDF
Mohd Esa
PDF
Study and Simulation of Seven Level - Ten Switch Inverter Topology
PDF
Harmonic Analysis of Three level Flying Capacitor Inverter
PDF
THD analysis of SPWM & THPWM Controlled Three phase Voltage Source Inverter
PDF
Common Mode Voltage reduction in Diode Clamped MLI using Alternative Phase Op...
PDF
CMV analysis of 5-level Cascaded H-Bridge MLI with equal and unequal DC sourc...
PDF
INVESTIGATION OF COMMON MODE VOLTAGE IN 5-LEVEL DIODE CLAMPED MLI USING CARRI...
The Science of Success-Coursera certificate 3
Coursera certificate 2
Coursera certificate 1
Multilevel Inverter and Multipliers
Design and Verification of 4 X 4 Wallace Tree Multiplier
RTL Verification and FPGA Implementation of 4x4 Vedic Multiplier
Mohd Esa
Study and Simulation of Seven Level - Ten Switch Inverter Topology
Harmonic Analysis of Three level Flying Capacitor Inverter
THD analysis of SPWM & THPWM Controlled Three phase Voltage Source Inverter
Common Mode Voltage reduction in Diode Clamped MLI using Alternative Phase Op...
CMV analysis of 5-level Cascaded H-Bridge MLI with equal and unequal DC sourc...
INVESTIGATION OF COMMON MODE VOLTAGE IN 5-LEVEL DIODE CLAMPED MLI USING CARRI...

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
Construction Project Organization Group 2.pptx
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPT
Mechanical Engineering MATERIALS Selection
PPT
Total quality management ppt for engineering students
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Sustainable Sites - Green Building Construction
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPT
introduction to datamining and warehousing
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Construction Project Organization Group 2.pptx
Safety Seminar civil to be ensured for safe working.
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Mechanical Engineering MATERIALS Selection
Total quality management ppt for engineering students
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Sustainable Sites - Green Building Construction
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
R24 SURVEYING LAB MANUAL for civil enggi
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
III.4.1.2_The_Space_Environment.p pdffdf
introduction to datamining and warehousing
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT

Matlab-free course by Mohd Esa

  • 1. MATLAB/Simulink Free Course to beginners by Mohd Esa 1Mohd Esa
  • 4. Contents 1. Introduction 2. Basic Plotting 3. Matrices In MATLAB 4. M-File Programming 5. Control Systems 6. Digital Signal Processing 7. Modelling and control of DC Motor 8. Modelling and simulation of DC-DC converter (Buck Converter) 9. Simulation of DC-AC Converter(Voltage Source inverter) 10. Mathematical Modelling Using SimScape(Electrical Systems) 11. Laplace and Inverse Laplace Transformations using MATLAB 12. Fourier and Inverse Fourier Transformations Using MATLAB 13. Digital electronics Circuits 14. Filters using various Windows 15. Step Responses of P,I,D,PI,PD,PID Controllers 4Mohd Esa
  • 5. 1.Introduction • The name MATLAB stands for MATrix LABoratory.MATLAB is a high-performance language for technical computing. • It integrates computation, visualization, and programming environment. Furthermore, MATLAB is a modern programming language environment: it has sophisticated data structures, contains built-in editing and debugging tools, and supports object- oriented programming. • These factor make MATLAB an excellent tool for teaching and research. 5Mohd Esa
  • 6. Starting MATLAB When you start MATLAB, a special window called the MATLAB desktop appears. The desktop is a window that contains other windows. The major tools within or accessible from the desktop are: • The Command Window • The Command History • The Workspace • The Current Directory • The Help Browser • The Start button 6Mohd Esa
  • 7. 7
  • 8. Using MATLAB as a calculator • As an example of a simple interactive calculation, just type the expression you want to evaluate. Let’s start at the very beginning. For example, let’s suppose you want to calculate the expression, 1 + 2 × 3. You type it at the prompt command (>>) as follows, >> 1+2*3 ans =7 • You will have noticed that if you do not specify an output variable, MATLAB uses a default variable ans, short for answer, to store the results of the current calculation. Note that the variable ans is created (or overwritten, if it is already existed). To avoid this, you may assign a value to a variable or output argument name. For example, >> x = 1+2*3 x =7 • will result in x being given the value 1 + 2 × 3 = 7. This variable name can always be used to refer to the results of the previous computations. Therefore, computing 4x will result in >> 4*x ans = 28.0000 8Mohd Esa
  • 10. Example The value of the expression y = 𝑒−𝑎 sin(x) + 10√y, for a = 5, x = 2, and y = 8 is computed by >> a = 5; x = 2; y = 8; >> y = exp(-a)*sin(x)+10*sqrt(y) y =28.2904 The subsequent examples are >> log(142) ans = 4.9558 >> log10(142) ans = 2.1523 Note the difference between the natural logarithm log(x) and the decimal logarithm (base 10) log10(x). To calculate sin(π/4) and 𝑒10 , we enter the following commands in MATLAB, >> sin(pi/4) ans = 0.7071 >> exp(10) ans =2.2026e+004 10Mohd Esa
  • 11. Quitting MATLAB • To end your MATLAB session, type quit in the Command Window, (or) select File −→ Exit MATLAB in the desktop main menu. 11Mohd Esa
  • 12. 2.Basic plotting • MATLAB has an excellent set of graphic tools. Plotting a given data set or the results of computation is possible with very few commands. You are highly encouraged to plot mathematical functions and results of analysis as often as possible. • Trying to understand mathematical equations with graphics is an enjoyable and very efficient way of learning mathematics. • Being able to plot mathematical functions and data freely is the most important step, and this section is written to assist you to do just that. 12Mohd Esa
  • 13. Plotting Example-1 The MATLAB command to plot a graph is plot (x,y). The vectors x = (1, 2, 3, 4, 5, 6) and y = (3, −1, 2, 4, 5, 1) produce the picture shown >> x = [1 2 3 4 5 6]; >> y = [3 -1 2 4 5 1]; >> plot(x,y) 13Mohd Esa
  • 14. Plotting Example-2 • For example, to plot the function sin (x) on the interval *0, 2π+, we first create a vector of x values ranging from 0 to 2π, then compute the sine of these values, and finally plot the result >> x = 0:pi/100:2*pi; >> y = sin(x); >> plot(x , y) – starts at 0, – takes steps (or increments) of π/100, – stops when 2π is reached. 14Mohd Esa
  • 15. Adding titles, axis labels, and annotations >> xlabel(’x = 0:2pi’) >> ylabel(’Sine of x’) >> title(’Plot of the Sine function’) 15Mohd Esa
  • 16. Multiple data sets in one plot • Multiple (x, y) pairs arguments create multiple graphs with a single call to plot. For example, these statements plot three related functions of x: y1 = 2 cos(x), y2 = cos(x), and y3 = 0.5 ∗ cos(x), in the interval 0 ≤ x ≤ 2π. >> x = 0:pi/100:2*pi; >> y1 = 2*cos(x); >> y2 = cos(x); >> y3 = 0.5*cos(x); >> plot(x,y1,’--’,x,y2,’-’,x,y3,’:’) >> xlabel(’0 leq x leq 2pi’) >> ylabel(’Cosine functions’) >> legend(’2*cos(x)’,’cos(x)’,’0.5*cos(x)’) >> title(’Typical example of multiple plots’) >> axis([0 2*pi -3 3]) 16Mohd Esa
  • 17. 17
  • 18. Specifying line styles and colors • It is possible to specify line styles, colors, and markers (e.g., circles, plus signs, . . . ) using the plot command: plot(x,y,’style_color_marker’) where style_color_marker is a triplet of values from below table 18Mohd Esa
  • 19. 3.Matrices in Matlab • The purpose of this section is to show how to create vectors and matrices in MATLAB.An array of dimension 1 ×n is called a row vector, whereas an array of dimension m × 1 is called a column vector. The elements of vectors in MATLAB are enclosed by square brackets and are separated by spaces or by commas. 19Mohd Esa
  • 20. Row & Column Vector To enter a row vector, v, type >> v = [1 4 7 10 13] v = 1 4 7 10 13 Column vectors are created in a similar way, however, semicolon (;) must separate the components of a column vector, >> w = [1;4;7;10;13] w = 1 4 7 10 13 20Mohd Esa
  • 21. Converting Row Vector into Column Vector • A row vector is converted to a column vector using the transpose operator. The transpose operation is denoted by an apostrophe or a single quote (’). • >> w = v’ w = 1 4 7 10 13 21Mohd Esa
  • 22. Entering a matrix • A matrix is an array of numbers. To type a matrix into MATLAB you must • begin with a square bracket, [ • separate elements in a row with spaces or commas (,) • use a semicolon (;) to separate rows • end the matrix with another square bracket, ] 22Mohd Esa
  • 23. Example • Here is a typical example. To enter a matrix A, such as, >> A = [1 2 3; 4 5 6; 7 8 9] • MATLAB then displays the 3 × 3 matrix as follows, A = 1 2 3 4 5 6 7 8 9 23Mohd Esa
  • 24. Correction Through Indexing • Correcting any entry is easy through indexing. Here we substitute A(3,3)=9 by A(3,3)=0. The result is >> A(3,3) = 0 A = 1 2 3 4 5 6 7 8 0 24Mohd Esa
  • 25. Determining Dimensions of a Matrix • To determine the dimensions of a matrix or vector, use the command size. For example, • >> size(A) ans = 3 3 means 3 rows and 3 columns 25Mohd Esa
  • 26. Transposing a matrix • The transpose operation is denoted by an apostrophe or a single quote (’). It flips a matrix • about its main diagonal and it turns a row vector into a column vector. Thus, >> A’ ans = 1 4 7 2 5 8 3 6 0 26Mohd Esa
  • 27. Matrix Athematic >> C = A.*B C = 10 40 90 160 250 360 490 640 810 >> A.^2 ans = 1 4 9 16 25 36 49 64 81 27Mohd Esa
  • 28. Matrix inverse • >> A = [1 2 3; 4 5 6; 7 8 0]; >> inv(A) ans = -1.7778 0.8889 -0.1111 1.5556 -0.7778 0.2222 -0.1111 0.2222 -0.1111 >> det(A) ans = 27 28Mohd Esa
  • 30. 4.M-Files in MATLAB • A script file is an external file that contains a sequence of MATLAB statements. Script files have a filename extension .m and are often called M-files. M-files can be scripts that simply execute a series of MATLAB statements, or they can be functions that can accept arguments and can produce one or more outputs. 30Mohd Esa
  • 31. Example-1 of M-File • Use the MATLAB editor to create a file: File → New → M-file. A = [1 2 3; 3 3 4; 2 3 3]; b = [1; 1; 2]; x = Ab Save the file, for example, example1.m. • Run the file, in the command line, by typing: >> example1 x = -0.5000 1.5000 -0.5000 31Mohd Esa
  • 32. Example-2 of M-File(Same example previously executed in command window) Plot the following cosine functions, y1 = 2 cos(x), y2 = cos(x), and y3 = 0.5 ∗ cos(x), in the interval 0 ≤ x ≤ 2π. • Create a file, say example2.m, which contains the following commands x = 0:pi/100:2*pi; y1 = 2*cos(x); y2 = cos(x); y3 = 0.5*cos(x); plot(x,y1,’--’,x,y2,’-’,x,y3,’:’) xlabel(’0 leq x leq 2pi’) ylabel(’Cosine functions’) legend(’2*cos(x)’,’cos(x)’,’0.5*cos(x)’) title(’Typical example of multiple plots’) axis([0 2*pi -3 3]) Run the file by typing example2 in the Command Window. 32Mohd Esa
  • 33. Program to compute area of circle To print results in a MATLAB function we use the the fprintf statement. The syntax is very similar to the corresponding C command. The function input allows the user to provide input data from the keyboard. A simple example is below. Function area circle % interactive program to compute area of circle r = input(’Give radius of circle : ’); a = pi*rˆ2; fprintf(’The area of circle with radius %.2f is %.6f n’, r, a); 33Mohd Esa
  • 34. 5.Control Systems TRANSFER FUNCTION FROM ZEROS AND POLES MATLAB PROGRAM: z=input(‘enter zeroes’) p=input(‘enter poles’) k=input(‘enter gain’) [num,den]=zp2tf(z,p,k) tf(num,den) EXAMPLE: Given poles are -3.2+j7.8,-3.2-j7.8,-4.1+j5.9,-4.1-j5.9,-8 and the zeroes are - 0.8+j0.43,-0.8-j0.43,-0.6 with a gain of 0.5 34Mohd Esa
  • 35. ZEROS AND POLES FROM TRANSFER FUNCTION MATLAB PROGRAM: num = input(‘enter the numerator of the transfer function’) den = input(‘enter the denominator of the transfer function’) [z,p,k] = tf2zp(num,den) EXAMPLE: 35Mohd Esa
  • 36. STEP RESPONSE OF A TRANSFER FUNCTION num = input(‘enter the numerator of the transfer function’) den = input(‘enter the denominator of the transfer function’) step(num,den) 36Mohd Esa
  • 37. IMPULSE RESPONSE OF A TRANSFER FUNCTION num = input(‘enter the numerator of the transfer function’) den = input(‘enter the denominator of the transfer function’) impulse(num,den) 37Mohd Esa
  • 38. ROOT LOCUS FROM A TRANSFER FUNCTION PROGRAM: num=input(‘enter the numerator of the transfer function’) den=input(‘enter the denominator of the transfer function’) h=tf(num,den) rlocus(h) 38Mohd Esa
  • 39. BODE PLOT FROM A TRANSFER FUNCTION PROGRAM: num=input('enter the numerator of the transfer function') den=input('enter the denominator of the transfer function') h=tf(num,den) [gm pm wcp wcg]=margin(h) bode(h) 39Mohd Esa
  • 40. TRANSFER FUNCTION FROM STATE MODEL MATLAB PROGRAM: A =input(‘enter the matrix A’) B= input(‘enter the matrix B’) C = input(‘enter the matrix C’) D= input(‘enter the matrix D’) Sys =ss2tf(A,B,C,D) 40Mohd Esa
  • 41. STATE MODEL FROM TRANSFER FUNCTION There are three methods for obtaining state model from transfer function: 1. Phase variable method 2. Physical variable method 3. Canonical variable method Out of three methods given above canonical form is probably the most straightforward method for converting from the transfer function of a system to a state space model is to generate a model in "controllable canonical form.“ PROGRAM: num=input(‘enter the numerator of the transfer function’) den=input(‘enter the denominator of the transfer function’) ss(tf(num,den)) 41Mohd Esa
  • 42. STATE MODEL FROM ZEROS AND POLES PROGRAM: z=input('enter zeros') p=input('enter poles') k=input('enter gain') [A,B,C,D]=zp2ss(z,p,k) 42Mohd Esa
  • 43. STEP RESPONSE OF A STATE MODEL PROGRAM: A=input(‘enter matrix A’) B=input(‘enter matrix B’) C=input(‘enter matrix C’) D=input(‘enter matrix D’) Step(A,B,C,D) 43Mohd Esa
  • 44. IMPULSE REPONSE OF A STATE MODEL PROGRAM: A=input('enter matrix A') B=input('enter matrix B') C=input('enter matrix C') D=input('enter matrix D') impulse(A,B,C,D) 44Mohd Esa
  • 45. RAMP RESPONSE OF A STATE MODEL PROGRAM: t=0:0.01:10; u=t A=input('enter matrix A') B=input('enter matrix B') C=input('enter matrix C') D=input('enter matrix D') lsim(A,B,C,D,u,t) 45Mohd Esa
  • 46. NYQUIST PLOT FROM TRANSFER FUNCTION PROGRAM: num=input(‘enter the numerator of the transfer function’) den=input(‘enter the denominator of the transfer function’) h=tf(num,den) nyquist(h) [gm pm wcp wcg]=margin(h) if(wcp>wcg) disp(‘system is stable’) else disp(‘system is unstable’) end 46Mohd Esa
  • 47. 6.Circuit Theorems • Superposition theorem • Thevenins Theorem • Norton's Theorem 47Mohd Esa
  • 48. Super Position Theorem Find Currents in each Branch 48Mohd Esa
  • 49. Step-1 Take only One Emf Source 20v while short Circuit other 49Mohd Esa
  • 50. Step-1 Take only One Emf Source 28 V while short Circuit other 50Mohd Esa
  • 51. Total currents in different branches are 51Mohd Esa
  • 52. Superposition Theorem Program clc; E1=input('enter the source voltage 1:'); E2=input('enter the source voltage 2:'); disp('first step:'); r1=input('enter resistance 1:'); r2=input('enter resistance 2:'); r3=input('enter resistance 3:'); disp('total resistance in first step is'); rftotal=(r1+((r2*r3)/(r2+r3))); disp(rftotal) disp('current through resistance R1:'); if1=E1/rftotal; disp(if1) disp('current through resistance R2:'); if2=(if1*(r3/(r3+r2))); disp(if2) disp('current through resistance R3:'); if3=(if1*(r2/(r3+r2))); disp(if3) disp('second step:'); disp('total resistance in second step is'); rstotal=(r2+((r3*r1)/(r1+r3))); disp(rstotal) disp('current through resistance R2:'); is2=E2/rstotal; disp(is2) disp('current through resistance R1:'); is1=(is2*(r3/(r3+r1))); disp(is1) disp('current through resistance R3:'); is3=(is2*(r1/(r1+r3))); disp(is3) disp('The total currents in different branches are:'); disp('current through resistance R1:'); i1=if1-is1; disp(i1) disp('current through resistance R2:'); i2=is2-if2; disp(i2) disp('current through resistance R3:'); i3=if3+is3; disp(i3) 52Mohd Esa
  • 53. Program Result enter the source voltage 1:20 enter the source voltage 2:28 first step: enter resistance 1:8 enter resistance 2:10 enter resistance 3:12 total resistance in first step is 13.4545 current through resistance R1: 1.4865 current through resistance R2: 0.8108 current through resistance R3: 0.6757 second step: total resistance in second step is 14.8000 current through resistance R2: 1.8919 current through resistance R1: 1.1351 current through resistance R3: 0.7568 The total currents in different branches are: current through resistance R1: 0.3514 current through resistance R2: 1.0811 current through resistance R3: 1.4324 53Mohd Esa
  • 56. Thevenins Theorem Program E1=input('enter the source voltage:'); r1=input('enter resistance r1:'); r2=input('enter resistance r2:'); rload=input('enter the load resistance:'); r=input('enter resistance of voltage source:'); disp('Equivalent emf of the network:'); disp('current in the network before load resistance is connected'); i=(E1/(r1+r2+r)); disp(i) disp('voltage across terminals LM:'); Eth=i*r2; disp(Eth) disp('Equivalent resistance of the network:'); rth=((r2*(r1+r))/(r2+(r1+r))); disp(rth) disp('current in load resistance:'); il=(Eth/(rth+rload)); disp(il) 56Mohd Esa
  • 59. Nortons Theorem Program E1=input('enter the source voltage:'); r1=input('enter resistance r1:'); r2=input('enter resistance r2:'); r3=input('enter resistance r3:'); r4=input('enter resistance r4:'); disp('short circuit current is:'); In=E1/r1; disp(In) disp('Nortans Resistance Rn is:'); Rn=((r1*(r3+r4))/(r1+r3+r4)); disp(Rn) disp('current through resistance r2 is:'); i=(In*(Rn/(Rn+r2))); disp(i) 59Mohd Esa
  • 61. 7.Digital Signal Processing • Representation of Basic Signals • Fast Fourier Transform • Inverse Fast Fourier Transform 61Mohd Esa
  • 62. Representation of basic signals %Unit Impulse Signal% n1=input('Enter the no of samples'); x1=[-n1:1:n1]; y1=[zeros(1,n1),ones(1,1),zero s(1,n1)]; subplot(2,3,1); stem(x1,y1); xlabel('Time Period'); ylabel('Amplitude'); title('Unit Impulse Signal'); %Unit Step Signal% n2=input('Enter the no of samples'); x2=[0:1:n2]; y2=ones(1,n2+1); subplot(2,3,2); stem(x2,y2); xlabel('Time Period'); ylabel('Amplitude'); title('Unit Step Signal'); %Unit Ramp Signal% n3=input('Enter the no of samples'); x3=[0:1:n3]; subplot(2,3,3); stem(x3,x3); xlabel('Time Period'); ylabel('Amplitude'); title('Unit Ramp Signal'); %Exponential Signal% n4=input('Enter the length of the signal'); a=input('Enter the value of a:'); x4=[0:1:n4]; y4=a*exp(x4); subplot(2,3,4); stem(x4,y4); xlabel('Time Period'); ylabel('Amplitude'); title('Exponential Signal'); %Sinusoidal Signal% x5=[-pi:0.1:pi]; y5=sin(2*pi*x5); subplot(2,3,5); plot(x5,y5); xlabel('Time Period'); ylabel('Amplitude'); title('Sinusoidal Signal'); %Cosine Signal% x6=[-pi:0.1:pi]; y6=cos(2*pi*x5); subplot(2,3,6); plot(x6,y6); xlabel('Time Period'); ylabel('Amplitude'); title('Cosine Signal') 62Mohd Esa
  • 64. Fast Fourier Transform-Program %Fast Fourier Transform% x=input('enter the input sequence'); n=input('enter the length of the sequence'); subplot(2,1,1); stem(x); xlabel('time'); ylabel('amplitude'); title(‘Input Sequence’); y1=fft(x,n); subplot(2,2,2); stem(y1); xlabel('time'); ylabel('amplitude'); title(‘Fast fourier Transform’); 64Mohd Esa
  • 66. Inverse Fast Fourier Transform-Program %Inverse Fast Fourier Transform% x=input('enter the input sequence'); n=input('enter the length of the sequence'); subplot(3,1,1); stem(x); xlabel('time'); ylabel('amplitude'); title(‘input sequence’); xk=ifft(x,n); magxk=abs(xk); anglexk=angle(xk); k=0:1:n-1; subplot(3,1,2); stem(k,magxk); xlabel('time'); ylabel('amplitude'); title('mag plot'); subplot(3,1,3); stem(k,anglexk); xlabel('time'); ylabel('amplitude'); title('phase plot'); 66Mohd Esa
  • 68. Modelling and control of DC Motor 68Mohd Esa
  • 72. Block Diagram of DC Motor 72Mohd Esa
  • 74. Matlab Simulation of DC motor in Open Loop 74Mohd Esa
  • 75. Simulation Results for dc motor open loop 75Mohd Esa
  • 76. Closed loop speed control of DC Motor using PI Controller 76Mohd Esa
  • 78. 8.DC-DC Converter Simulation (Buck Converter) 78Mohd Esa
  • 79. Simulation results for Buck Converter 79Mohd Esa
  • 80. Simulink Parameters (Buck Converter) Formula Calculated Value 𝛼 = 𝑉0 𝑉𝑔 𝛼 = 𝑉0 𝑉𝑔 = 5 12 =41.67% L= V0(1−α)Ts ∆I0 ;∆I0 = 0.5A L=291.65e-6 H C= ∆𝐼0 8∆𝑉0 𝑓𝑠 ; ∆𝑉0 = 20𝑚𝑉 C=156.25e-6 F Switching Frequency 20kHz Load Resistance 23 Ohms 80Mohd Esa
  • 82. Pulses generation Using SPWM 82Mohd Esa
  • 87. THD Analysis of Line Voltage 87Mohd Esa
  • 88. 10.Mathematical Modelling Using SimScape (Electrical Systems) Simscape provides an environment for modeling and simulating physical systems spanning mechanical, electrical, hydraulic, and other physical domains. It provides fundamental building blocks from these domains that you can assemble into models of physical components, such as electric motors,inverting op-amps, hydraulic valves, and ratchet mechanisms. 88Mohd Esa
  • 89. Features of SimScape • Single environment for modeling and simulating mechanical, electrical, hydraulic, thermal, and other multidomain physical systems • Libraries of physical modeling blocks and mathematical elements for developing custom components • MATLAB based Simscape language, enabling text-based authoring of physical modeling components, domains, and libraries • Physical units for parameters and variables, with all unit conversions handled automatically • Ability to simulate models that include blocks from related physical modeling products without purchasing those products • Support for C-code generation 89Mohd Esa
  • 90. SimScape Libraries Simscape block library contains two libraries that belong to the Simscape™ product: • Foundation library — Contains basic hydraulic, pneumatic, mechanical, electrical, magnetic, thermal, thermal liquid, and physical signal blocks, organized into sublibraries according to technical discipline and function performed • Utilities library — Contains essential environment blocks for creating Physical Networks models • In addition, if you have installed any of the add-on products of the Physical Modeling family, you will see the corresponding libraries under the main Simscape library. 90Mohd Esa
  • 91. Foundation Libraries • Simscape Foundation libraries contain a comprehensive set of basic elements and building blocks, such as: • Mechanical building blocks for representing one- dimensional translational and rotational motion • Electrical building blocks for representing electrical components and circuits • Magnetic building blocks that represent electromagnetic components 91Mohd Esa
  • 92. • Hydraulic building blocks that model fundamental hydraulic effects and can be combined to create more complex hydraulic components • Pneumatic building blocks that model fundamental pneumatic effects based on the ideal gas law • Thermal building blocks that model fundamental thermal effects • Thermal liquid building blocks that model fundamental thermodynamic effects in liquids • Physical Signals block library that lets you perform math operations on physical signals, and graphically enter equations inside the physical network • Using the elements contained in these Foundation libraries, you can create more complex components that span different physical domains. You can then group this assembly of blocks into a subsystem and parameterize it to reuse and share these components. 92Mohd Esa
  • 93. Utilities Library • In addition to Foundation libraries, there is also a Simscape Utilities library, which contains utility blocks, such as: • Solver Configuration block, which contains parameters relevant to numerical algorithms for Simscape simulations. Each Simscape diagram (or each topologically distinct physical network in a diagram) must contain a Solver Configuration block. • Simulink-PS Converter block and PS-Simulink Converter block, to connect Simscape and Simulink® blocks. Use the Simulink-PS Converter block to connect Simulink outports to Physical Signal inports. Use the PS-Simulink Converter block to connect Physical Signal outports to Simulink inports. 93Mohd Esa
  • 96. Electrical System Using SimScape • In this example, you are going to model an electrical system and makes you familiar with using the basic SimScape blocks. 96Mohd Esa
  • 99. 11.Laplace and Inverse Laplace Transformations using MATLAB Laplace Transforms: In this example, we will compute the Laplace transform of some commonly used functions. 99 Program Result syms s t a b w laplace(a) laplace(t^2) laplace(t^9) laplace(exp(-b*t)) laplace(sin(w*t)) laplace(cos(w*t)) ans = 1/s^2 ans = 2/s^3 ans = 362880/s^10 ans = 1/(b + s) ans = w/(s^2 + w^2) ans = s/(s^2 + w^2) Mohd Esa
  • 100. Inverse Laplace Transform MATLAB allows us to compute the inverse Laplace transform using the command ilaplace. Program Result syms s t a b w ilaplace(1/s^7) ilaplace(2/(w+s)) ilaplace(s/(s^2+4)) ilaplace(w/(s^2 + w^2)) ilaplace(s/(s^2 + w^2)) ans = t^6/720 ans = 2*exp(-t*w) ans = cos(2*t) ans = sin(t*w) ans = cos(t*w) 100Mohd Esa
  • 101. 12.Fourier and Inverse Fourier transformations Using MATLAB Program For Fourier Transformation syms x f = exp(-2*x^2); %our function ezplot(f,[-2,2]) % plot of our function FT = fourier(f) % Fourier transform The following result is displayed − FT = (2^(1/2)*pi^(1/2)*exp(-w^2/8))/2 Plotting the Fourier transform as − ezplot(FT) 101Mohd Esa
  • 102. Inverse Fourier Transform MATLAB provides the ifourier command for computing the inverse Fourier transform of a function. For example 102Mohd Esa
  • 111. 14-Filters using Various windows • Filters Low pass filters High pass filters Band pass filters Band stop filters • Windows Rectangular Hamming Hanning Blackman 111Mohd Esa
  • 112. Low Pass Filter Low pass filter Program: clc; clear all; N=50; wc=0.5*pi; b=fir1(N,(wc/pi),rectwin(N+1)); w=0:.001:pi; H=freqz(b,1,w); plot(w,abs(H)) %replace rectwin with hamming/hanning/Blackman windows 112Mohd Esa
  • 113. LPF with rectangular window 113Mohd Esa
  • 114. LPF with Hamming Window 114Mohd Esa
  • 115. LPF with Hanning Window 115Mohd Esa
  • 116. LPF with Blackman Window 116Mohd Esa
  • 117. High Pass Filter clc; clear all; N=50; wc=0.5*pi; b=fir1(N,(wc/pi),'high',rectwin(N+1)); w=0:.001:pi; H=freqz(b,1,w); plot(w,abs(H)) %replace rectwin with hamming/hanning/Blackman windows 117Mohd Esa
  • 118. HPF with Rectangular Window 118Mohd Esa
  • 119. HPF with Hamming Window 119Mohd Esa
  • 120. HPF with Hanning Window 120Mohd Esa
  • 121. HPF with Blackman Window 121Mohd Esa
  • 122. Band Pass Filter clc; clear all; N=50; wc1=0.5*pi; wc2=0.6*pi; b=fir1(N,[wc1/pi,wc2/pi],'bandpass',rectwin(N+1)); w=0:.001:pi; H=freqz(b,1,w); plot(w,abs(H)) %replace rectwin with hamming/hanning/Blackman windows 122Mohd Esa
  • 123. BPF with rectangular Window 123Mohd Esa
  • 124. BPF with Hamming Window 124Mohd Esa
  • 125. BPF with Hanning Window 125Mohd Esa
  • 126. BPF with Blackman Window 126Mohd Esa
  • 127. Band Stop Filter clc; clear all; N=50; wc1=0.5*pi; wc2=0.6*pi; b=fir1(N,[wc1/pi,wc2/pi],'stop',rectwin(N+1)); w=0:.001:pi; H=freqz(b,1,w); plot(w,abs(H)) %replace rectwin with hamming/hanning/Blackman windows 127Mohd Esa
  • 128. BSF with Rectangular Window 128Mohd Esa
  • 129. BSF with Hamming Window 129Mohd Esa
  • 130. BSF with Hanning Window 130Mohd Esa
  • 131. BSF with Blackman Window 131Mohd Esa
  • 132. Step Responses of P,I,D,PI,PD,PID Controllers P Controller (kp=1) clc clear all close all kp=input('enter the value of kp'); num=[1+kp]; den=[1,20,10+kp]; h=tf(num,den); step(h) figure g=feedback(h,1); step(g) figure step(h,g) figure nyquist(g) figure bode(g) 132Mohd Esa
  • 134. I Controller(ki=1) clc clear all close all ki=input('enter the value of ki'); num=[1+ki]; den=[1,20,10,ki]; h=tf(num,den); step(h) figure g=feedback(h,1); step(g) figure step(h,g) figure nyquist(g) figure bode(g) 134Mohd Esa
  • 136. D Controller(kd=1) clc clear all close all kd=input('enter the value of kd'); num=1; den=[1,(20+kd),10]; h=tf(num,den); step(h) figure g=feedback(h,1); step(g) figure step(h,g) figure nyquist(g) figure bode(g) 136Mohd Esa
  • 138. PD Controller (kp=1;kd=2) clc clear all close all kd=input('enter the value of kd'); kp=input('enter the value of kp'); num=1+kp; den=[1,20+kd,10+kp]; h=tf(num,den); step(h) figure g=feedback(h,1); step(g) figure step(h,g) figure nyquist(g) figure bode(g) 138Mohd Esa
  • 140. PI Controller(kp=1,ki=2) clc clear all close all kp=input('enter the value of kp'); ki=input('enter the value of ki'); num=[kp,ki]; den=[1,20,10+kp,ki]; h=tf(num,den); step(h) figure g=feedback(h,1); step(g) figure step(h,g) figure nyquist(g) figure bode(g) 140Mohd Esa
  • 142. PID Controller (kp=1;ki=2;kd=3) clc clear all close all kp=input('enter the value of kp'); ki=input('enter the value of ki'); kd=input('enter the value of kd'); num=[1+ki]; den=[1+kd,20+kp,10+ki]; h=tf(num,den); step(h) figure g=feedback(h,1); step(g) figure step(h,g) figure nyquist(g) figure bode(g) 142Mohd Esa