Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
39 views

Matlab Imp Intro

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Matlab Imp Intro

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 88

MSME Tool Room, Bhubaneswar

Central Tool Room and Training Centre (CTTC), Bhubaneswar


B-36, Chandaka Industrial Area, Odisha, Bhubaneswar - 751024
Phone: 91-674- 3011700 to 3011755 Fax: 91-674-3011750
Web site- www.cttc.gov.in, E-mail: cttc@cttc.gov.in
SIMULINK
CONTENTS

 Introduction
 Types of Function
 Sharing Data using Global memory
 Preserving data between calls to a function
 String Function
INTRODUCTION
 Simulink is a MATLAB-based graphical programming
environment for modeling, simulating and analyzing multi
domain dynamical systems. Its primary interface is a
graphical block diagramming tool and a customizable set of
block libraries.

 For modeling, simulink provides a graphical user interface


(GUI) for building models as block diagrams, using click-
and-drag mouse operations.

Developer: MathWorks
License: Proprietary
Operating system: Linux, macOS, Microsoft Windows
OTHER FEATURES
 Simulink includes a comprehensive block library of sinks, sources, linear and
nonlinear components, and connectors.

 We can also customize and create our own blocks.


 Models are hierarchical, so we can build models. using both top-down and bottom-up
approaches.
 We can view the system at a high level and then double-click blocks to go down
through the levels and thus visualize the model details.
OTHER FEATURES
 In simulink, using scopes and other display blocks,
we can see the simulation results while these
simulation is running.
 In addition, we can change many parameters and
see what happens.
 The simulation results can be put in the MATLAB
workspace for post processing and visualization.
 Everything is in graphically instead of typical
m.code
OTHER FEATURES
 It supports linear and nonlinear systems modeled in continuous time,
discrete time, or a hybrid of the two.
 The simulink model can be applied for modeling various time-varying
systems that includes:

 Control Systems
 Signal Processing Systems
 Video Processing Systems
 Image Processing Systems
 Communication
 Satellite Systems
 Ship Systems
 Automotive Systems
 Monetary Systems
STARTING SIMULINK
Simulink is started from the MATLAB command prompt by entering the following command:
simulink
Alternatively, you can hit the Simulink button at the top of the MATLAB window as shown here:
STARTING SIMULINK
Once you click on Blank Model, a new window will appear as shown below.
STARTING SIMULINK
When it starts, Simulink brings up a single window, entitled Simulink Start Page which can be seen here.
MATLAB SIMULINK - BLOCKS
Blocks in Simulink helps to create models. You can make use of a
Simulink library browser that has different types of blocks for
creating a model.

The two ways to select the blocks are as follows −


 Using Simulink browser library.
 Searching for block inside model canvas.
USING SIMULINK BROWSER LIBRARY

Simulink library browser To bring the block inside your model

Simulink search option


Click the block and add to your current model
SEARCHING FOR BLOCK INSIDE MODEL CANVAS
Another way to add blocks to your model is to click inside the model and type the name of the block. It will
search in the library browser and list all the model as per what you have typed.
SAVE FILE
Here all the file save in .slx formate
BASIC
CONFIGURATION
IN
SIMULINK
EXAMPLE

Signal Amplification
To create a simple model of Gain Amplifier,

We need following blocks:


 Sine Wave To generate an input signal for the –model
 Gain To increase the amplitude of input signal.
 Scope - To visualize the signals in the model
SIMULATION

You can varry the gain and sine wave amplitude as per your requirement
SIMULATION (INPUT + OUTPUT)

You can vary the gain and sine wave amplitude as per your requirement
PLOTTING IN DIFFERENT SECTION
SIMULATION (BY MUX)

You can vary the gain and sine wave amplitude as per your requirement
CREATING MODEL ANNOTATION & SIGNAL LABELING

Annotations provide textual information about a model.


We can add an annotation to any unoccupied area of our block diagram.
To create a model annotation, double-click an unoccupied area of the
block diagram.
A small rectangle appears and the cursor changes to an insertion point.
Start typing the annotation contents.
TITTLE NAME OF MODEL
EDIT INDIVISUAL COMPONETS NAME
MODIFYING THE BLOCKS
Resizing a block
Left-click on a block and drag the corner of the
block to resize it.
Changing the color of a block
Foreground and Background color of a block
can be changed
Click on the Format menu
Select Foreground and Background color.
Disconnecting a block
Left-Click, hold "Shift Key" and drag a block
to disconnect the block from the model
LEBELING SIGNAL

Double click on the signal to type label


Left-click and move the label anywhere on the signal
An attempt to move else where, the label will snap back to the
signal
SCOPE MANAGER
Click Here @
2021 version

Click on
Viewers Manager
SCOPE MANAGER
Add number of
viewer

Viewer’s Point
are Created
FLOATING SCOPE
The Floating Scope is a sink block from the Simulink/Sinks library in the Simulink Library
Browser. This block is similar to the Scope block, but it does not have any input ports! Instead, you
can select any signals in your model and view them on the Floating Scope.

Unlock & Link it to which


signal need to show
DATA EXPORTING FROM SIMULINK TO MATLAB
Data can be export from Simulink to MATLAB workspace for further
processing.
To perform this, we have to connect to Workspace block in the model
from library browser.

You can see in workspace


You can see in workspace

a=out.tout;
% under out we need tout values
b=out.simout.signals.values
% under out > simout > signals > values
% TO ACCUMULATE ALL VARIABLE IN % TO SAVE IN EXCEL FOTMATE
SINGLE EXCEL SHEET % first change the location where you want
a=out.tout; to save the excel sheet
b=out.simout.signals.values;
c=[a b] xlswrite('my data',c)

ANSWER
c =

0 0 0
0.2000 3.9734 1.9867
0.4000 7.7884 3.8942
0.6000 11.2928 5.6464
0.8000 14.3471 7.1736
1.0000 16.8294 8.4147
1.2000 18.6408 9.3204
1.4000 19.7090 9.8545
1.6000 19.9915 9.9957
1.8000 19.4770 9.7385
2.0000 18.1859 9.0930
…. … …
COLLECT DATA FROM SCOPE AND SAVE IT IN EXCEL
DATA IMPORTING FROM EXCEL SHEET

d=xlsread('my data');
% Read your excel sheet & save it to a variable.
DATA IMPORTING FROM EXCEL SHEET
SIGNAL ROUTING (BUS CREATOR/BUS SELECTOR)
When you have numbers of block are more , it’s very difficult to routing the signal.
So we use these two option to minimize the connection between two or numvbers
For Example : blocks
SIGNAL ROUTING (BUS CREATOR/BUS SELECTOR)
The Bus Creator block combines a set of signals into a bus, i.e., a group of signals represented by a
single line in a block diagram.

The Bus Selector block accepts input from a Bus Creator block or another Bus Selector block. This
block has one input port. The number of output ports depends on the state of the Muxed output check
box.
SIGNAL ROUTING (BUS CREATOR)

Bus Creator numbers of block


SIGNAL ROUTING (BUS SELECTOR)

Bus Selector numbers signals require to monitor


SIGNAL ROUTING (BUS CREATOR/BUS SELECTOR)
SIGNAL ROUTING (GO TO – FROM)

Change the Tag name for doing multiple option


CREATING SUB SYSTEM IN SIMULINK

Subsystems are useful when your model gets big and complex. You
can change a part of the model into a subsystem that helps to keep
the flow very clean and understandable.

A subsystem can be virtual or nonvirtual.


A virtual subsystem provides graphical hierarchy in a model.
A nonvirtual subsystem provides graphical hierarchy and executes
as a unit within a model.
CREATING SUB SYSTEM IN SIMULINK

We will change the value of the constant as 10 and 20. The


result 10+20 = 30 should be seen inside the display block.

Let us add one more block named Unary minus that will
change the output from 30 to -30
CREATING SUB SYSTEM IN SIMULINK

Now, let us select the portion i.e. the sum and the Unary
minus block to create a subsystem

Click on Create Subsystem. Once done, the sum block


and the Unary minus block will be converted into a
subsystem
PRELOAD CONSTANT VALUE
When we design some big model we have to take assumption of different variable as constant. And
later on we will add the value to get our desire result.

Initially it will show error


PRELOAD CONSTANT VALUE

Steps:
1. Save the model.
2. Close the model
3. Reopen the model again
4. Do the setting in
MODELLING > Model Settings > Model Properties > Callbacks > PreLoadFcn > Assign the value
USE OF MATLAB INBUILT FUNCTION IN SIMULINK

You can check all the inbuilt function available in matlab


USER DEFINE FUNCTION (MATLAB FUNCTION)
The Simulink Function block is a subsystem block preconfigured as a starting point for graphically
defining a function with Simulink® blocks. The block provides a text interface to function callers. You can
call a Simulink Function block from a Function Caller block, a MATLAB Function block, or a Stateflow ® chart.

Steps:
1. Drag & Drop Matlab Function
2. Double click on that block
3. In command prompt its create a function file
4. Modified the function as per your requirement.
USER DEFINE FUNCTION (MATLAB FUNCTION)

Steps:
1. Drag & Drop Matlab Function
2. Double click on that block
3. In command prompt its create a function file Example we want to check:
4. Modified the function as per your requirement. function distance = dist2(x1,y1,x2,y2)
5. Automatically the function input change as per function % distance between two points
% syntax: distance=dist2(x1,y1,x2,y2)
distance=sqrt((x2-x1)^2+(y2-y1)^2);
USER DEFINE FUNCTION (MATLAB FUNCTION)
SOLVER BLOCK
MATH OPERATION
SIMULINK
MATH OPERATIONS

Mathematical function blocks such as Gain, Product, and Sum


BASIC ARITHMETIC OPERATION
Example:

86+24/(14-2)

Answer : 88

Any type of mathematical


arithmetic operation can be
possible in Simulink by these
block
BASIC ARITHMETIC OPERATION
Example:

Answer : 2
SOLUTION
EXAMPLE
y(t) = 2Sin(t) + 5Sin(2t) - 10
Following are the steps to solve the equation −
 Get a Sine wave block. Right click and select block parameters. Select sign type as time based. Change
the amplitude to 2 and frequency to 1. That will be 2Sin(t).
 Get another sine wave block. Now, set the amplitude to 5 and frequency to 2 to display 5Sin(2t). Select
sign type as time based.
 Now get an add block and add both sine waves.
 Get a constant. Right click and select block parameters. Change the value from 1 to 10.
 Get a subtract block where one input will come from step 3 and another from constant i.e. step 4.
 Get a scope block and connect the input from step 6 to it.
EXAMPLE
y(t) = 2Sin(t) + 5Sin(2t) - 10

Amp-2 & Frq-1

Amp-5 & Frq-2


ELECTRICAL CIRCUIT ANALYSIS (EQUIVALENT RESISTANCE)

From Ohm’s Law


1. Equivalent resistance formula for series resistance

2. Equivalent resistance formula for parallel resistance


EQUIVALENT RESISTANCE
Example :
EQUIVALENT RESISTANCE
SOLUTION :
EQUIVALENT RESISTANCE IN SIMULINK
Blocks Require(SIMSCAPE>SPECIALIZED POWER SYSTEM
1. Series RLC Branch
2. DC Voltage Source
3. Voltage Measurement
4. Current Measurement
5. Display
6. Divide Block
QUESTION-1
Find the equivalent resistance

Voltage you may take anything


Answer-6
QUESTION-2
Find current through 4 resistance.
QUESTION-2

Answer I3 = 3.6 amp


GENERATE SINGLE PHASE SUPPLY WAVE FORM
GENERATE SINGLE PHASE SUPPLY WAVE FORM

Voltage-220v ac

Frequency-50Hz

Sample time
GENERATE THREE PHASE SUPPLY WAVE FORM

Each phase having 120 deg apart


from each others
GENERATE THREE PHASE SUPPLY WAVE FORM
mag u
Specify the amplitude of the three-phase output signal.

angle u
Specify the angle, in degrees, of the three-phase output
signal.

Freq
Specify the frequency, in hertz, of the three-phase
output signal.

abc
Returns the three-phase signal.

wt
Angle (rad) varying between 0 and 2*pi, synchronized on
zero crossings of the fundamental (positive-sequence) of
phase A.
GENERATE THREE PHASE SUPPLY WAVE FORM

Change the sample time -0.1

A zero-crossing is a point where the sign of a


mathematical function changes
DESIGN RECTIFIER (HALF WAVE UN-CONTROLLED)
DESIGN RECTIFIER (HALF WAVE & FULL WAVE)
ALL MOTOR CONTROL BLOCK
AC MOTOR (SINGLE PHASE & 3 PHASE)

DC MOTOR
SERIES,SHUNT,COMOPOUND

SPECIAL MOTOR (PID BASED)


(UNIVERSAL, BRUSHLESS DC , STEPPER, SERVO)
BLOCKS
Abs Output absolute value of input
Add Add or subtract inputs
Algebraic Constraint Constrain input signal
Assignment Assign values to specified elements of signal
Bias Add bias to input
Complex to Magnitude-Angle Compute magnitude and/or phase angle of complex signal
Complex to Real-Imag Output real and imaginary parts of complex input signal
Divide Divide one input by another
Dot Product Generate dot product of two vectors
Find Nonzero Elements Find nonzero elements in array
Gain Multiply input by constant
Magnitude-Angle to Complex Convert magnitude and/or a phase angle signal to complex signal
Math Function Perform mathematical function
MinMax Output minimum or maximum input value
MinMax Running Resettable Determine minimum or maximum of signal over time
Permute Dimensions Rearrange dimensions of multidimensional array dimensions
BLOCKS
Polynomial Perform evaluation of polynomial coefficients on input values
Product of Elements Copy or invert one scalar input, or collapse one non scalar input
Product, Matrix Multiply Multiply and divide scalars and non scalars or multiply and invert matrices
Real-Imag to Complex Convert real and/or imaginary inputs to complex signal
Reshape Change dimensionality of signal
Rounding Function Apply rounding function to signal
Sign Indicate sign of input
Sine Wave Function Generate sine wave, using external signal as time source
Slider Gain Vary scalar gain using slider
Sqrt Calculate square root, signed square root, or reciprocal of square root
Squeeze Remove singleton dimensions from multidimensional signal
Trigonometric Function Specified trigonometric function on input
Unary Minus Negate input
Vector Concatenate, Matrix
Concatenate Concatenate input signals of same data type for iterative processing
Weighted Sample Time Math Support calculations involving sample time
EQUATION TO MODEL
THANK YOU

You might also like