2. What is MATLAB & SIMULINK?
MATLAB is an interactive computational
environment for mathematical
calculation as well as to solve
engineering problems through
programming.
SIMULINK an associate of MATLAB which
uses graphical programming approach
to simulate dynamical systems
3. How to start MATLAB?
Double click on the MATLAB icon. First time MATLAB opens with several windows. Close all windows except
Command window. Yes keep only command window.
4. Click on layout tab and from the dropdown menu select
Command window only. So you will see only command
Window.
This is the MATLAB command prompt >> where you will enter MATLAB command(s) and press enter key
5. MATLAB program
>>edit an editor window appears either separately or at the upper part of
command window depending on the version you use.
Press ctrl+S keys. Save as dialog
Appears.In that enter file name
To run the program enter file
name at command prompt and
press enter key to get result
6. Simulink –A basic introduction
Simulink can be thought of as a graphical programming approach. In Simulink you
use block diagram format to formulate the simulation.
You get the blocks from various Simulink libraries and toolboxes , connect them as
a pattern , set simulation parameters , run the simulation and get the graphical
result
To get Simulink type simulink at command prompt >>simulink [PEK]
Simulink library browser appears. In that click as shown
A model window appears. In that we create your
Simulink simulation.
7. To connect the blocks click
the outport of first block
drag the mouse with left
mouse button and join at the
Inport of second block. These
two blocks will be connected
by a straight line as shown
To simulate press the run button
.After run double click the
Scope block to view output
9. To simulate power electronic circuits we have to use
components in the Simpowersytems library. For this type
>> powerlib at the command prompt
Next we will Simulate a Half wave Rectifier in Simulink using
powerlib components
10. Simulation of a simple half wave rectifier with simulink
As said earlier first you should know which component is available from which Library. For this simulation we use
the following components.
Component Library Path to get and icon
AC voltage source Electrical sources
Powerlib Electrical sources AC voltage source
Diode Power electronics PowerlibPower electronicsdiode
Voltage
measurement
Measurements PowerlibMeasurementsVoltage measurement
Resistance-series
RLC branch
Scope
Elements
sinks
PowerlibElementsseries RLC branch in that choose only R
14. After connection
Set the time to 0.1
After that press the simulation
Button to start simulation
Press Ctrl+S buttons and save
After simulation double click on
scope block. Click the sixth button
from left to get the proper output
In latest version this may differ little
bit which I have shown next
You can drag at the corner to
Increase the size of scope
16. GENERAL PLOT COMMANDS
• Plot(x,y) x – x variable as a row vector y- y variable as a row vector
• xlabel(‘ label name’) x- axis name with the name within single quote
• ylabel(‘ label name’) y- axis name with the name within single quote
• title(‘ title name’) – Graph title with the title within single quote
• axis([xmin xmax ymin ymax]) – To define x and y axis limits
• legend(‘graph1’,’graph 2’,’graph 3’) – to show legend on multiple graphs
• gtext(‘ curve name’) – To indicate curves through mouse click
• grid – To add grid lines to the graph
17. Subplots
In one big graph you
show
Small graphs
The syntax is
subplot(m,n,r)
m= number of rows
n=number of columns
r= picture number
counted from
Top to bottom with
scanning from left to
right in Z manner
The subplot is followed
by usual plot commands
18. Your Simulink model and the driving program should reside in the same folder which is your current working folder
1. First create a Simulink model and save by a suitable name
2. Next drag and drop a subsystem block form port & subsystems library
3. Double click on the scope block and click on second icon
4. Scope parameters dialog appears. In that click the History tab. Remove the top tick mark and put the tick mark in the
second.
5. Give a suitable name to variable here We have given as x and for format choose as Array
6. Click Apply and then OK button
19. Create the following MATLAB program to run simulation and get graph
% Simulation of damped sinusoidal oscillator
%
% File name :dsoscs.m
%
sim('dsosc'); % This is the Simulink simulation command with the Simulink file name
%
plot(x(:,1),x(:,2)),xlabel('t(s)'),ylabel('x(t)=5.e^{-0.2t}.sin(omegat-pi/2)')
title('Damped Signal Generator'),grid
Save the file as dsoscs . The first column of x is time while second column is actual values
20. That’s all my dear
Folks! Thank you for your
patient Listening.
Practice! Practice! Practice!