You are on page 1of 50

# Applications of MATLAB and Introduction to Simulink

By V V S Narayana Medasani

Application of MATLAB in fundamental signal generation: Fundamental signals: 1. Unit impulse 2. Unit step 3. 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:
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]);

Output:

Alternate method of generation of Unit step signal using MATLAB function :
MATLAB code:
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]);

Output:

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

Output:

Application of MATLAB in Fourier Transform:

Example 1(Fourier Transform):
MATLAB code:
syms t f u=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:
Output:
u = syms t f U=pi*dirac(f) - i/f; (pi + pi*(2*heaviside(t) u=ifourier(U,t)
- 1))/(2*pi)

Note: simplify(u)

ans = heaviside(t)

Application of MATLAB in Fourier Transform:

Example 2(Fourier transform):
MATLAB code:
syms t f u=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 f U=pi*(dirac(f - 1) + dirac(f + 1)); u=ifourier(U,t))
Note: simplify(u)

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

ans = cos(t)

Application of MATLAB in Laplace Transform:

Example 1(Laplace Transform):
MATLAB code:
syms t s u=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 s U=1/s; u=ilaplace(U,t)

Output:
u = 1

Application of MATLAB in Laplace Transform:

Example 2(Laplace transform):
MATLAB code:
syms t s u=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 s U=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 z u=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 -Ascii load data.txt disp(data)

Output:
1100 1233 1111 1222 999 800 650 1001 1300 1221

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

Output:
T = 800 1100 650 1233 1001 1111 1300 1222 1221 999

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

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

MATLAB code:
syms x f=3*x^3; D=diff(f) I=int(D)

Output:
D = 9*x^2

I = 3*x^3

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

1. Modeling/designing systems 2. signal processing design/simulation

Simulink runs under Matlab. First start Matlab, then type “simulink” at the Matlab prompt (Or) By directly click on Simulink icon

The first window that pops up is the Library Browser.

This is a library of blocks that are available for putting into the Simulink block diagram.

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.

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

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

Connecting blocks:

Drag a signal line from the output of a block to the input of another block. (or) Ctrl-Click will automatically connect.

Running the simulation:
Change parameters under Simulation | Configuration Parameters. (or) Ctrl-E will automatically opens Configuration Parameters.

Running the simulation:
Set start and stop time for the simulation 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 to the 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.

You can add text comments anywhere in the block diagram by double clicking and typing in some text. You can change the default comments 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 the CTRL 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 the summer 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 function numerator and denominator polynomials by double-clicking on the transfer function block.

Transfer Functions:
U s  H s  1 s 1 s 1 1 s  s  1

Y s  U s H s 

1 1   s s 1 Applying Inverse Laplace transform gives y  t   1  et  u  t 

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

Integrators:
For integrators, you can set the initial condition and limit the output to not be allowed to go above or below some value on the properties for that block.

User defined functions:
You can embed user-defined mfiles using the “Embedded MATLAB Function” 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……