50
Applications of MATLAB and Introduction to Simulink By V V S Narayana Medasani

Applications of MATLAB and Introduction to Simulink

Embed Size (px)

DESCRIPTION

MATLAB

Citation preview

Page 1: Applications of MATLAB and Introduction to Simulink

Applications of MATLAB and Introduction to Simulink

ByV V S Narayana Medasani

Page 2: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in fundamental signal generation:

Fundamental signals:1. Unit impulse2. Unit step3. Ramp

Page 3: Applications of MATLAB and Introduction to Simulink

Generation of Unit impulse signal using MATLAB :

MATLAB code:t=-1:0.1:1;dirac(t)

Output:>> dirac(0)ans =

Inf

>> dirac(1)ans = 0

>> dirac(-1)ans = 0

Page 4: Applications of MATLAB and Introduction to Simulink

Generation of Unit step signal using MATLAB :

MATLAB code: Output:t=-10:0.01:10;u=heaviside(t);plot(t,u);xlabel('t');ylabel('u(t)');title('Unit Step');axis([-10,10,0,1.2]);

Page 5: Applications of MATLAB and Introduction to Simulink

Alternate method of generation of Unit step signal using MATLAB function :

MATLAB code: Output:function y=step(n)y=n>=0;end

t=-10:0.01:10;u=step(t);plot(t,u);xlabel('t');ylabel('u(t)');title('Unit Step');axis([-10,10,0,1.2]);

Page 6: Applications of MATLAB and Introduction to Simulink

Generation of ramp signal using MATLAB :

MATLAB code: Output:t=-10:0.01:10;r=t.*heaviside(t);plot(t,r);xlabel('t');ylabel('r(t)');title('Ramp signal');

Page 7: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Fourier Transform:

Example 1(Fourier Transform):

MATLAB code:syms t fu=heaviside(t);U=fourier(u,f)

Output:U = pi*dirac(f) - i/f

Page 8: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Fourier Transform:Example 1(Inverse Fourier Transform):

MATLAB code:syms t fU=pi*dirac(f) - i/f;u=ifourier(U,t)

Output:u = (pi + pi*(2*heaviside(t) - 1))/(2*pi)

Note:simplify(u) ans = heaviside(t)

Page 9: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Fourier Transform:

Example 2(Fourier transform):

MATLAB code:syms t fu=cos(t);U=fourier(u,f)

Output:U = pi*(dirac(f - 1) + dirac(f + 1))

Page 10: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Fourier Transform:

Example 2(Inverse Fourier transform):

MATLAB code:syms t fU=pi*(dirac(f - 1) + dirac(f + 1));u=ifourier(U,t))

Output:u = (1/exp(t*i))/2 + exp(t*i)/2

Note:simplify(u) ans = cos(t)

Page 11: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Laplace Transform:

Example 1(Laplace Transform):

MATLAB code:syms t su=heaviside(t);U=laplace(u,s)

Output:U = 1/s

Page 12: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Laplace Transform:Example 1(Inverse Laplace Transform):

MATLAB code:syms t sU=1/s;u=ilaplace(U,t)

Output:u = 1

Page 13: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Laplace Transform:

Example 2(Laplace transform):

MATLAB code:syms t su=cos(t);U=laplace(u,s)

Output:U = s/(s^2 + 1)

Page 14: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in laplace Transform:

Example 2(Inverse Laplace transform):

MATLAB code:syms t sU=s/(s^2 + 1);u=ilaplace(U,t)

Output:u = cos(t)

Page 15: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Z-Transform:

Example (Z-Transform):

MATLAB code:syms n zu=2^n;U=ztrans(u)

Output:U = z/(z - 2)

Page 16: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in z-Transform:

Example (Inverse z-Transform):

MATLAB code:syms n z

U=z/(z-2);u=iztrans(U,n)

Output:u = 2^n

Page 17: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Root locus generation:

MATLAB code:num=[1 1];den=[1 5 6 7];sys=tf(num,den);rlocus(sys)

Output:

Page 18: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Bode plot generation:

MATLAB code:num=[1 1];den=[1 5 6 7];sys=tf(num,den);bode(sys)

Output:

Note:[gm,pm,wcg,wcp]=margin(sys)

Page 19: Applications of MATLAB and Introduction to Simulink

Application of MATLAB in Nyquist plot generation:

MATLAB code:num=[1 1];den=[1 5 6 7];sys=tf(num,den);nyquist(sys)

Output:

Page 20: Applications of MATLAB and Introduction to Simulink

Reading and writing data from files:

MATLAB code: M = [1100 800;1233 650; 1111 1001; 1222 1300; 999 1221];save data.txt M -Asciiload data.txtdisp(data)

Output:1100 8001233 6501111 10011222 1300999 1221

Page 21: Applications of MATLAB and Introduction to Simulink

Operations on loaded files:

MATLAB code: M = [1100 800;1233 650; 1111 1001; 1222 1300; 999 1221];save data.txt M -Asciiload data.txtT =rot90(data)

Output: T =

800 650 1001 1300 1221 1100 1233 1111 1222 999

Page 22: Applications of MATLAB and Introduction to Simulink

Some advanced MATLAB functions:

MATLAB code:

x = input('Enter a value:' );fprintf('The entered value is: ''%d''\n',x)

Output:Enter a value:1The entered value is: '1'

Page 23: Applications of MATLAB and Introduction to Simulink

Some advanced MATLAB functions:

MATLAB code:

syms xf=3*x^3;D=diff(f)I=int(D)

Output:D = 9*x^2 I = 3*x^3

Page 24: Applications of MATLAB and Introduction to Simulink

Some advanced MATLAB functions:

MATLAB code:

u=menu('The name of a person who is in water is jal andhar singh. what is his name when he is comes out of water','jal bhahar singh','jal andhar singh'); if u==1 disp('Your answer is wrong') else disp('Your answer is correct') end

Page 25: Applications of MATLAB and Introduction to Simulink

Introduction to Simulink:

Need for simulink:1. Modeling/designing systems2. signal processing design/simulation

Page 26: Applications of MATLAB and Introduction to Simulink

Starting of Simulink:

Simulink runs under Matlab. First start Matlab, then type “simulink” at the Matlab prompt

(Or)By directly click on Simulink icon

Page 27: Applications of MATLAB and Introduction to Simulink

Simulink Library:

The first window thatpops up is the LibraryBrowser.

This is a library ofblocks that areavailable for puttinginto the Simulink blockdiagram.

Page 28: Applications of MATLAB and Introduction to Simulink

Simulink Library:

A Simulink model is a block diagram. Click “File-New-Model” in the Library Browser or press Ctrl+N. An empty block diagram will pop up. You can drag blocks into the diagram from the library.

Page 29: Applications of MATLAB and Introduction to Simulink

Simulink Sources:

Select “sources” from the library.Drag any block you want to useinto the model.

Page 30: Applications of MATLAB and Introduction to Simulink

Simulink Sinks:

Select “sinks” from the library.Drag any block you want to useinto the model.

Page 31: Applications of MATLAB and Introduction to Simulink

Connecting blocks:

Drag a signal line from the output of a block to the input of anotherblock.

(or)Ctrl-Click will automatically connect.

Page 32: Applications of MATLAB and Introduction to Simulink

Running the simulation:

Change parameters underSimulation | ConfigurationParameters.(or)Ctrl-E will automatically opens Configuration Parameters.

Page 33: Applications of MATLAB and Introduction to Simulink

Running the simulation:

Set start andstop time for thesimulation here.

Page 34: Applications of MATLAB and Introduction to Simulink

Running the simulation:

Double click on the scope icon to open up the viewer.

Page 35: Applications of MATLAB and Introduction to Simulink

Running the simulation:

You often have to zoom out using the binocular icon if the curve doesn’t fit in the default axes.

Page 36: Applications of MATLAB and Introduction to Simulink

Running the simulation:

You can save data from the scope tothe workspace using the “Parameters”,“Data History” tab.

Page 37: Applications of MATLAB and Introduction to Simulink

Modifying block properties:

Double click on any block to bring up a properties box.Here are the “sine wave”properties.

Page 38: Applications of MATLAB and Introduction to Simulink

Adding comments:

You can add text comments anywhere in the block diagram by double clicking and typing in some text.

You can change the defaultcomments under the blocks by double clicking and editing the text.

Page 39: Applications of MATLAB and Introduction to Simulink

Signal Routing:

You can create a branch point in a signal line by holding down theCTRL key, and clicking on the line.

A summer block can be found in the “commonly used blocks” library, and in the “math” library.

Page 40: Applications of MATLAB and Introduction to Simulink

Signal Routing:To change the shape of thesummer to rectangular, or to add additional inputs or change the sign, double click on the summer.

You can flip a block over by right clicking and looking under “Format”, or by selecting it and typing CTRL-i

Page 41: Applications of MATLAB and Introduction to Simulink

Signal Routing:Under the “signal routing” library, the MUX block can be used to bundle a group of signals together into a single line.

The DEMUX block does the reverse.

This can be useful to send multiple signals to the same scope; then both signals will be displayed on the same plot.

Page 42: Applications of MATLAB and Introduction to Simulink

Transfer Functions:

You set the transfer functionnumerator and denominatorpolynomials by double-clickingon the transfer function block.

Page 43: Applications of MATLAB and Introduction to Simulink

Transfer Functions:

1

1

11

1

1 1

1Applying Inverse Laplace transform gives

1 t

U ss

H ss

Y s U s H ss s

s s

y t e u t

Page 44: Applications of MATLAB and Introduction to Simulink

Integrators and Differentiators:

Integrators and derivatives are available in the “continuous” library.

Page 45: Applications of MATLAB and Introduction to Simulink

Integrators:

For integrators, you can set theinitial condition and limit theoutput to not be allowed to goabove or below some value onthe properties for that block.

Page 46: Applications of MATLAB and Introduction to Simulink

User defined functions:

You can embed user-defined m-files using the “Embedded MATLABFunction” block under the “user defined functions” library.

Page 47: Applications of MATLAB and Introduction to Simulink

User defined functions:

A dc of 2 V is added to the input signal

Page 48: Applications of MATLAB and Introduction to Simulink

Introduction to GUI:

Guide :

The MATLAB Graphical User Interface Development Environment,provides a set of tools for creating graphical user interfaces (GUIs).

Page 49: Applications of MATLAB and Introduction to Simulink

Queries…………….

Page 50: Applications of MATLAB and Introduction to Simulink

The End……