0% found this document useful (0 votes)
61 views10 pages

Matlab Material

The document provides an overview of MATLAB and Simulink, detailing different types of developers, workspaces, and file types. It explains various blocks and their functions, including logical operators, subsystems, and data types, as well as guidelines from the Mathwork Automotive Advisory Board (MAAB). Additionally, it covers testing methodologies like Model in the Loop (MIL) testing and the importance of stateflow in dynamic systems.

Uploaded by

sravanipandla21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views10 pages

Matlab Material

The document provides an overview of MATLAB and Simulink, detailing different types of developers, workspaces, and file types. It explains various blocks and their functions, including logical operators, subsystems, and data types, as well as guidelines from the Mathwork Automotive Advisory Board (MAAB). Additionally, it covers testing methodologies like Model in the Loop (MIL) testing and the importance of stateflow in dynamic systems.

Uploaded by

sravanipandla21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Matlab Notes

It has two types of developers

 MBD(model based development) engineer - uses matlab simulink


 Script enginner/developers -

 Workspace is saved as .mat file.


 Script part is saved as .m file. They are 2 types of .m files
1. matlab scripting
2. matlab function.
 Simulink environment is saved as .slx file.

We cannot save the command window. editor window can be saved but not cmd window.

Workspaces: 3 types of workspaces:


1) Matlab/base workspace (By default)
2) Model workspace
3) Function workspace - function part it creates its own workspace

clear - to clear workspace, clc - to clear cmd window

The variables defined in base workspace can be used/shared/transfer to all models. -


public/selfless workspace.
The variables defined in model workspace cannot be used/shared/transfer to any other models. -
private/selfish workspace
The parameters/variables in both base and model workspace, the priority is given to model
workspace variables.

Saturation Block:
It is used to eradicate overflow and underflow conditions.
Lower Limit/Min and Upper Limit/max values are defined and we can only enter value in
between that range.

Switch: It is used to develop/design a single and simple if-else logic.(one if, one else).

Manual Switch: It has two input ports and is already connected with upper input. To connect to
lower input double-click on the switch.

Multiport Switch: It has a minimum of 3 inputs and one control port. The control port is used to
select the required input port.

Logical Operators:

NOT: In this the negation value is given. 0 gives 1 vice versa.


1 = active/high/on/true
0 = not active/low/off/false
all conditions should satisfy -AND Gate
any one condition should satisfy - OR Gate

Sub-system: It is used to remove or reduce the visual complexity. Select the components and
use ctrl+G subsystem is created.

Inport/outports are used to send/transfer their values between various sub systems.

Relational Operators:

Terminator: It is used to end/terminate a extra output, which is not used.


Ground: It is used to end/terminate a extra input, which is not used or not required.
Sum block: To avoid signal crossing. It is used in feedback loops.
Add: It takes two inputs and gives addition as output.

Mux: Any no.of inputs single output. It accepts only similar data types. In mux we cannot choose
the output datatype.
Demux: Single input and multiple output.
Bus: Bus accepts dissimilar data type inputs. In bus we can choose the datatype of the output.

Difference between Bus and Mux:


If we have same datatype signals we can use mux. Different datatype signals use Bus creator.
If we use Bus, we get code in the form of structure. If datatypes are similar we get code in
form of array in bus.
If we use Mux, we get code in the form of array.

Data types in simulink environment: double, single, int8/16/32/64, uint8/16/32/64,


boolean

Product block: It has no.of inputs and only one output.


Gain Block: It has only one input and one output. It is used to multiply input value.

Different type of Sub-systems: 2 types


 Atomic/non-virtual /controllable/conditional
 Non-atomic/virtual/non-controllable/non-conditional
Atomic subsystem borderlines are thick when compared to non-atomic.
Atomic subsystems are controllable subsystems.
Ex:
Enabled subsystem:
It is a controllable subsystem. When enable port value is >0 it gives output.
It is <0 the subsystem is in off/disabled state. Output will be zero.
We can pass numerical or wave form to enable sub system.
Held state: This is default state. In held the output is held after reaching negative value and
resumed from where it was hold.

Reset State: In this the output after reaching negative value is reset to zero and again the output
starts from there.

There is no difference in output between held and reset state when numerical values are used.

Triggered subsystem:

There are 4 types of triggers rising, falling, either, function call.


Only wave form has to be given as input to enable the subsystem. If numerical value is given
its output is 0.
No reset state in this subsystem. Default state is held.

How to design simple counter – shot0027.png


While designing the counter you get a error called algebraic loop error. This error occurs when
we connect the output directly to input port. This error can be eradicated using Delay(unit)
block placing it in the conncetion.

In this the count starts from 1. To start count from 0 change the initial value of unit
delay block from 0 to -1.****interview question****
To change the counter value to a maximum of 10 we use switch block. -shot0028.png

ctrl + r - to rotate a block


ctrl + i - to rotate a block 180 degrees.

Down Counter: shot0029.png

Delay Blocks: 3 types of delay blocks


 Unit Delay : The delay length is 1 only. cannot change the length of delay.
 Delay(z-1): same as unit but can change the length of the delay.
 Delay(z-2): can change the length of the delay.

We can use memory block instead of delay unit to design a counter.

Stop time = Simulation time(10.0sec)

Solvers:Modeling > Model Settings > Solver Selection.


Solver is a numerical approximation method to solve any matrix problem.
Two types of Solvers:
1. Variable Step: default solver.
It takes less time, steps and analyses at the required periods/frequencies.
2. Fixed Step: In real time we use this solver to generate auto code.

Numerical approximation method: It is the method to solve matrix.

Merge Block:
 It takes any no.of inputs but only one output. Here output is most recently activated
input subsystem.
 It is applicable for only conditionally/atomic executed sub systems.
 Limitation: It is not applicable for virtual sub systems and we encouner an error.
 Error: An input signal to merge block must be orginate from a conditionally executed sub
system.

Merge and Mux Block Difference:


Merge takes any no.of inputs but only one output but, in Mux we can use output signal as
required. Mux combines all input signals and shows all in the scope output.
In mux we can give constants, waves, conditional and virtual subystems as input.
In Merge we can give only conditional subsystems as input.

MERGE

MUX

MAAB – Mathwork Automotive Advisory Board Guidelines


All automotive companies interact and prepare guidelines i.e. is MAAB. This guidelines are
maintained by Mathwork.
Uses:
 Easy to understand the model
 Robustness of the code will be less.
 Less hardware and power requirement.
 Documentation is easy.
This are divided into 3 categories.
1) Mandatory
 If we violate this guidelines there is malfunctioning.
2) Strongly recommended
 If we violate this guidelines the quality of the product is less.
3) Recommended
 If we violate this guidelines the appearance of the product is not good.
Examples of MAAB:
 Dont use underscores before starting of the name of block/sub system/filename.
 Dont use consecutive underscores.
 Dont give number infront of the name.
 Dont use spaces
 Use sum block instead of “+” symbol in feedback loops to avoid crossing of signals.
 To generate auto code we have to use standard blocks. Dont use physical blocks.

OEM – Original Equipment Manufacturers Ex: Toyota, Benz, Honda, Nissan, Renault, Audi,
FCA, Caterpillar
Service Based Companies: L&T, KPIT, Alten, Wipro, Infosys, Capgemini, Harman

Goto and From Block:


If there are many subsytems to avoid signal crossing and complexity we use this blocks.
The tag name of both Goto and the corresponding From block should be same. For every
Goto block there must be a From Block.

Data Store Write and Date Store Read Block:


 These are data storage blocks. They are same as Goto and From block but, it has an extra
data store memory block.
 The write block data is sent to memory block where it is stored and from there the data is
sent to read block.

Model in the Loop Testing (MIL Test):


Testing by assigning different test values in constant block is called manual testing.

In MIL testing the test cases are written in an excel sheet and are imported using a signal
builder the output is then verified with the expected output. The excel file should contain only
one sheet.
To import file double-click on signal builder in File menu > Import from file(select the test
case file.xlsx) and open. Then Placement for selected data > replace exsiting dataset > click
confirm > Click OK and Apply.

Ex: MIL test for simple addition block


In excel sheet time, input1, input2 and expected output are given and using signal builder
the inputs are given to add block and the subtraction block is used check the simulated output
with the expected output. The output should be zero.
Test cases can be developed using system requirement specifications(SRS) document or using
designed model.

MCDC – Modified Condition Decision Coverage


 The MCDC report is used to verify how well the testing has been performed.
 It is used to determine the minimum no.of test cases. For ‘N’ inputs the no.of test cases we
have to take is N+1, to get 100% test coverage.

User defined function blocks:

MATLAB Function Block:


To bring MATLAB function(scripting part) into the simulink environment it is used.
(System)S – Function Block:
Whenever you want to bring C- code into MATLAB simulink environment it is used.

Stateflow : If you want to design sudden changes in dynamic system we use stateflow.
Ex : Breaks, gear, indicators
Simulink : If you want to design continuous changes in dynamic system we use simulink.
Ex: steering
Library Browser > Stateflow
 Stateflow consists of 4 modules chart, sequence viewer, chart-transition table, truth table.
 The difference between stateflow(pale yellow) and simulink(white) is background color.
 Simulink is the product of MATLAB, Stateflow is the product of simulink.
 It is difficult and requires more no.of blocks to design sudden changes in simulink.
 In stateflow animation is possible but not in simulink.

The components in stateflow are:


State, Junction, Default transition, Box, Simulink State, Simulink Junction, Graphical function,
MATLAB Function.
To design stateflow for any system/module we should know the
A) No.of states
B) The condition for transition between states.
C) The default transition state of the module/system.
D) If a condition satisfies the action that has to be performed in that state.

Rules to follow while designing:


 Use square brackets to give conditions in stateflow
 In condition only use “= =” instead of “=”.
 In action we can use both ‘==’ or’=’ and have to end with ‘;’.

State Components:
1. Entry(en)
2. During(du)
3. Exit(ex)

Examples:
1.Functioning of Tubelight (x is output, u is input)
Default Transition

State Condition
2. System has 4 states. Transition can occur from State 1 to State 2 when input is greater
than 0. After 10 secs transition can occur from State 2 to State 3. After 15 msec transition
can occur from State 3 to State 4. After 5sec transition can occur from State 4 to State 1.

3.Traffic Lights System has 3 states(Red, yellow, green). Default transition is at yellow state.
After 4 sec transition occurs b/w yellow to green. When transition occurs yellow light
should be 0(OFF). After 3 sec transition occurs b/w green to red. When transition occurs
green light should be 0(OFF). After 2 secs transition occurs b/w red to yellow. When
transition occurs red light should be 0(OFF).
Absolute(ABS) Block: It performs modulus operation. If the input is negative or positive value it
gives only positive values as output.

Selector Block: To select a particular input signal from a no.of input signals we use selector
block. The input is selected as per index.

Selector

MUX

Decomposition Method: There are 2 types of methods


1. Exclusive(OR): In this only one state will be active if there are many states, but
execution is performed according to the execution order.
The State Blocks are showed with full border.

2. Parallel(AND): In this all the sates will be active at a time, but execution is performed
according to the execution order. We can change the execution order.
The state blocks are showed with dotted border lines.

Child States/
Sub States

Parent State
Min-Max Block : It gives max/min value as output from a given no.of inputs.

Interview Questions:
Matlab Model Life Cycle:

Requirements – Develop/Design – MIL test – Auto code generation – SIL test – PIL test – HIL
test.
SIL Test:
 Improve the quality of the product SIL test is carried out.
 We can use same test cases for MIL and SIL test. In SIL we can mainly focus on data types,
because we are working on the code here to check satisfying different conditions.
 It is used for rounding process.

Difference between validation and verification


In verification we manually check. Verification is a process in validation.
In validation we are using a tool to check the model.

You might also like