Applications of MATLAB and Introduction to Simulink

Preview:

DESCRIPTION

MATLAB

Citation preview

Applications of MATLAB and Introduction to Simulink

ByV V S Narayana Medasani

Application of MATLAB in fundamental signal generation:

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

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

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]);

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]);

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');

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

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)

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))

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)

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

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

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)

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)

Application of MATLAB in Z-Transform:

Example (Z-Transform):

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

Output:U = z/(z - 2)

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

Application of MATLAB in Root locus generation:

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

Output:

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)

Application of MATLAB in Nyquist plot generation:

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

Output:

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

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

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'

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

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

Introduction to Simulink:

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

Starting of Simulink:

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

(Or)By directly click on Simulink icon

Simulink Library:

The first window thatpops up is the LibraryBrowser.

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

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.

Simulink Sources:

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

Simulink Sinks:

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

Connecting blocks:

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

(or)Ctrl-Click will automatically connect.

Running the simulation:

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

Running the simulation:

Set start andstop time for thesimulation here.

Running the simulation:

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

Running the simulation:

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

Running the simulation:

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

Modifying block properties:

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

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.

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.

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

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.

Transfer Functions:

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

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

Integrators and Differentiators:

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

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.

User defined functions:

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

User defined functions:

A dc of 2 V is added to the input signal

Introduction to GUI:

Guide :

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

Queries…………….

The End……

Recommended