ee4314 lab 1 session matlab and simulink spring 2014 ta: joe sanford [email protected]...

78
EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford [email protected] (with special thanks to Suresh Sampathkumar and Md Ahsan Habib)

Upload: carmel-phelps

Post on 17-Jan-2016

224 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

EE4314 Lab 1 SessionMatlab and Simulink

Spring 2014

TA: Joe Sanford [email protected]

(with special thanks to Suresh Sampathkumar and Md Ahsan Habib)

Page 2: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

MATLAB Overview• When MATLAB launched, Command Window Appears• Command prompt(>>) in Command Windows to accept instruction or input• Objects → Data• Objects are placed in MATLAB workspace

>> a = 4; b = 3+2j; c = a * b;• whos → Another way to view workspace

>> whos• who → short version of whos -> reports only the names of workspace objects

>> who• clear a → remove specific variables (a) from the workspace

>> clear a• clc → clears the command window

>> clc• help -> most important and useful command for new users

>> help whos• exit -> terminates MATLAB

Page 3: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Algebra of Complex Numbers• Complex number: z = a + jb

• Re z = a; Im z = b• Complex number expressed in polar coordinates (r,θ)

• a = rcos θ, b = rsin θ, z = r(cos θ+ jsin θ)• Euler Formulae:

• ejθ=cos θ + jsin θ, z = r ejθ

• z = |z|ej∠z

• |z| = r = √(a2+ b2)• ∠z = θ = tan-1 (b/a), π≥ θ ≥-π

• Conjugate of z, z* = a – jb = r e-jθ= |z|e-j∠z

• zz* = (a+jb)(a-jb) = a2 + b2 = |z|2

• Useful Identities (7)• e∓jnπ = -1, n → odd integer e∓j(2n+1)π = -1, n → integer• e∓j2nπ = 1, n → integer

Page 4: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Complex Numbers – A common mistakez1 = a +jb

z2=-a -jb

θ1

θ2

∠ z1 = tan-1(b/a) = θ1

∠ z2 = tan-1(-b/-a) = θ2

∠ z2 ≠ ∠ z1

∠ z2 = θ2 = θ1 - 180

z1 = -a +jb

z2=a -jb

θ1

θ2

∠ z1 = tan-1(b/-a) = θ1

∠ z2 = tan-1(-b/a) = θ2

∠ z1 ≠ ∠ z2

∠ z1 = θ1 = 180 + θ2

Example B.1 (9)

Page 5: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Complex Numbers - MATLAB• Matlab predefines i = j =

>> z = -3-j4• real and imag operators extract real and imaginary components of z.

>> z_real = real(z)>> z_imag = imag(z)

• Modulus or Magnitude of a complex number•

>> z_mag = sqrt(z_real^2+z_imag^2)• |z|2 = zz*

>> z_mag = sqrt(z*conj(z))>> z_mag = abs(z)

• Angle of a complex number>> z_rad = atan2(z_mag, z_real)

• atan2 -> two-argument arc-tangent function; ensures the angle reflects in the proper quadrant.>> z_rad = angle(z)

• MATLAB function pol2cart number polar form to Cartesian form• z = 4 e-j(3π/4)

>> [z_real, z_imag] = pol2cart(-3*pi/4,4)

Page 6: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Complex Numbers - Exercise

• Determine z1z2 and z1/z2 if z1 = 3+j4 and z2 = 2+3j>> Verify your results using MATLAB• Convert your results from Cartesian coordinates to Polar coordinates>> Verify your results using MATLAB function pol2cart

(13)

Page 7: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

MATLAB - Vector Operation• Vectors of even valued integers

>> k = 0:2:11• Negative and non-integer step sizes

>> k = 11:-10/3:0• If step size not specified, value of one assumed

>> k = 0:11• In MATLAB, ascending positive integer indices specify particular vector elements.

>> k(5), k(1:4),• Vector representation to create signals

• 10 Hz sinusoid described by f(t) = sin(2π10t+π/6) when 0≤t<0.2>> t = 0:0.0004:0.2-0.0004; f = sin(2*pi*10*t+pi/6); f(1)

• Find the three cube roots of minus 1, • →

>> k = 0:2;>> w = exp(j*(pi/3 + 2*pi*k/3))

Exercise (56)

• Find the 50th cube root of minus 1?

Page 8: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Simple Plotting• MATLAB’s plot command

>> plot(t,f);• Axis labels are added using xlabel and ylabel

>> xlabel(‘t’); ylabel(‘f(t)’)• Plotting discrete points, 100 unique roots of w^100=-1

>> plot(real(w), imag(w), ‘o’);>> xlabel(‘Re(w)’); ylabel(‘Im(w)’);>> axis equal

Page 9: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Element by Element Operations• Multiplication, Division and Power• x = [5 4 6]; y = [1 2 3];

>> x_mul_y = x * y >> x_elem_mul_y = x.*y>> x_div_y = x/y>> x_elem_div_y = x./y>> x_elem_pow_y = x.^y

•Suppose h(t) = f(t)g(t) where g(t) = exp(-10*t)>> g = exp(-10*t);>> h = f.*g;>> plot (t,f,’-k’,t,h,’-b’);>> xlabel(‘t’); ylabel(‘Amplitude’);>> legend (‘f(t)’,’h(t));

h g(t)

Damped Sinusoid

Page 10: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Matrix Operations• Common Useful function

• eye(m) creates the m×m identity matrix>> eye(3)

• ones(m,n) creates the m×n matrix of all ones>> ones(2,3)

• zeros(m,n) creates the m×n matrix of all zeros>> zeros(3,2)

•Row vector>> r = [1 3 2];

•A 2×3 matrix>> A = [2 3; 4 5; 0 6];

Page 11: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Matrix Operations• Transpose

>> c= r’;• Concatenation

>> B = [c A];• Matrix inverse

>> D = inv(B);

• Matrix indices>> B(1,2)>> B(1:2,2:3)

• Colon can be used to specify all elements along a specified dimension

>> B(2,:)>> B(:,2)

Page 12: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Matrix Operations

Solve

• Ax = y; • x = A-1Ax = A-1y >> A = [1 -2 -3; -sqrt(3) 1 –sqrt(5); 3 –sqrt(7) 1]; >> y = [1; pi; exp(1)]; >> x = inv(A)*y

,

Page 13: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox

• Useful functions (example code to follow)

– tf(num, den) - creates a continuous-time transfer function with numerator(s) num and denominator(s) den.

– ss(a,b,c,d) - creates the continuous-time state-space model– impulse() - calculates the unit impulse response of a linear system.– step() - calculates the unit step response of a linear system.– lsim() - simulates the time response of continuous or discrete linear systems

to arbitrary inputs. – residue(b,a) - finds the residues, poles, and direct term of a partial fraction

expansion of the ratio of two polynomials, b(s) and a(s).– ode23() - solves initial value problems for ordinary differential equations.– Dsolve () – solves differential equations symbolically.

Page 14: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox (exa)

• How do we solve this in Matlab?– Define variables for numerator and denominator– Build a system

• Create a transfer function

– Show response to input

Page 15: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox (exa)>> Num = [1 1]Num = 1 1>> Den = [1 3 12]Den = 1 3 12>> sys = tf(Num, Den)

sys = s + 1 -------------- s^2 + 3 s + 12 Continuous-time transfer function.

>> impulse(sys)

What about the step response?

Page 16: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox (exa)

• This can also be done in a program!– This allows you to create complex systems with

individual blocks, each with their own dynamics!– Allows for multiple responses all at once (less

typing in command prompt)• For example:

– Time Response to arbitrary input>> t = 0 : 0.1 : 10;>> u = sin(2.*t);>> lsim(sys,u,t)

Page 17: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox (cont’d)

• What about Partial Fraction Expansions?– After defining system using Num, Den formulation

• Use “residue()” function>> [r,p,k] = residue(Num, Den)r = 0.5000 + 0.0801i 0.5000 - 0.0801ip = -1.5000 + 3.1225i -1.5000 - 3.1225ik = []

Can now be written as

Page 18: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox - Differential Equations

Matlab can only solve first order differential equations

So, what do you do then?

example

Page 19: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox - Differential Equations

• Convert Second Order system – Introduce intermediate variable

• In this case, the first derivative of the velocity

– Divide through by the mass, m

– Then introduce intermediate variable…

Page 20: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox - Differential Equations

= y(0) = 600z(0) = 0

Page 21: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox - Differential Equations

• Can use either ode45 or ode23 function• Must give system using only first order

equations• Let y be variable 1 and z be variable 2• Values will be returned by ODE function in

vector form– dy/dt first and dz/dt second

Page 22: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox - Differential Equations

Function rk = f(t,y)mass = 80;g = 9.81;rk = [y(2); -g + 4/15*y(2).^2/mass];

Page 23: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox - Differential Equations

clear alltimerange = [0 15]; %secondsinitialvalues = [600 0];[t, y]=ode45(@f, timerange, initialvalues)plot(t, y(:,1))ylabel(‘height (m)’)xlabel(‘time (s)’)

Page 24: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox

• Other Useful Functions to Review– det(sI-A)– poles(eig A)– ss(A,B,C,D)– lsim(sys,u,t,x0)

Page 25: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox – Stability Example

• Define Matrices– A = [ 0 1 0; 980 0 -2.8; 0 0 -100 ]; B = [ 0; 0; 100 ]; C = [ 1 0 0 ];

• Type in program or command window– poles = eig(A);– t = 0:0.01:2; – u = zeros(size(t)); – x0 = [0.01 0 0]; – sys = ss(A,B,C,0); – [y,t,x] = lsim(sys,u,t,x0); – plot(t,y)– title('Open-Loop Response to Non-Zero Initial Condition') – xlabel('Time (sec)') – ylabel(‘System Position(m)')

• What does the resultant plot show us about the system?• What about the output of the “poles = eig(A)” command?

Page 26: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control Systems Toolbox – Stability Example

• Stability of the System– The eigenvalues of the A matrix are the values of s

where det(sI - A) = 0. – equivalent to the poles of the transfer fucntion

• What about the graph?

Page 27: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Simulink!

(very exciting stuff)(no, really. It’s actually really, really powerful)

Page 28: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Simulink

• Simulink is a tool for simulating dynamic systems with a graphical interface specially developed for this purpose

• Dynamic systems are described by differential equations.

• Simulink is a numerical differential equation solver.

• Launch Simulink by typing in Matlab command prompt>> simulink

Page 29: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Create a new model

• Click the new-model icon in the upper left corner to start a new Simulink file

• Select the Simulink icon to obtain elements of the model

Page 30: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Your workspace

Library of elements Model is created in this window

Page 31: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Save your model

• You might create a new folder, like the one shown below, called simulink_files

• Use the .mdl suffix when saving

Page 32: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Example 1: a simple model

• Build a Simulink model that solves the differential equation

• Initial condition• First, sketch a simulation diagram of this

mathematical model (equation)

tx 2sin3.1)0( x

Page 33: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Simulation diagram

• Input is the forcing function 3sin(2t)• Output is the solution of the differential

equation x(t)

• Now build this model in Simulink

xxs1

3sin(2t)(input)

x(t)(output)

1)0( x

integrator

Page 34: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Select an input block

Drag a Sine Wave block from the Sources library to the model window

Page 35: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Select an operator block

Drag an Integrator block from the Continuous library to the model window

Page 36: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Select an output block

Drag a Scope block from the Sinks library to the model window

Page 37: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Connect blocks with signals

• Place your cursor on the output port (>) of the Sine Wave block

• Drag from the Sine Wave output to the Integrator input

• Drag from the Integrator output to the Scope input Arrows indicate the direction of the

signal flow.

Page 38: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Select simulation parameters

Double-click on the Sine Wave block to set amplitude = 3 and freq = 2.

This produces the desired input of 3sin(2t)

Page 39: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Select simulation parameters

Double-click on the Integrator block to set initial condition = -1.

This sets our IC x(0) = -1.

Page 40: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Select simulation parameters

Double-click on the Scope to view the simulation results

Page 41: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Run the simulation

In the model window, from the Simulation pull-down menu, select Start

View the output x(t) in the Scope window.

Page 42: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Simulation results

To verify that this plot represents the solution to the problem, solve the equation analytically.

The analytical result,

matches the plot (the simulation result) exactly.

ttx 2cos)( 23

21

Page 43: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Example 2• Build a Simulink model that solves the

following differential equation– 2nd-order mass-spring-damper system– zero ICs– input u(t) is a step with magnitude 1– parameters: m = 1, c = 0.5, k = 2

Page 44: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

(Continued)

Page 45: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

(Continued)

• You can flip the orientation of the block by right click > Format > Flip Block (under “Format” or hitting “Ctrl-I”

Page 46: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

(Continued)

• The last thing we need to do is to add all the signals together using ‘Sum’ block.

Page 47: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

(Continued)

• At this point, the model accurately solves the ordinary differential equation.

Page 48: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

(Continued)

• At this point, the model accurately solves the ordinary differential equation.

Page 49: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

(Continued)

u(t) Signal z(t) Signal

Page 50: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Introduction of Labview and myDAQ

By: Suresh Sampathkumar

Page 51: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Graphical programming language& Data flow

• LabVIEW relies on graphical symbols rather than textual language to describe programming actions

• The principle of dataflow, in which functions execute only after receiving the necessary data, governs execution in a straightforward manner

Page 52: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

How does LabVIEW work?

• LabVIEW programs are called:– Virtual Instruments (VIs) – because their appearance and operation imitate actual instruments.

• However, they are analogous to main programs, functions and subroutines from popular language like C, Fortran, Pascal, …

Page 53: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

LabVIEW Programs Are Called VirtualInstruments (VIs)• Front Panel

• Controls = Inputs• Indicators = Outputs

• Block Diagram• Accompanying “program”

for front panel• Components “wired”

together

Page 54: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

LabVIEW Introduction

• Two “sets” for development– Front Panel– Block Diagram

• Wiring connections

• LabVIEW Conventions

• Running LabVIEW programs

Page 55: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Controls Palette

• The Controls palette contains the controls and indicators you use to create the front panel.

Page 56: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

LabVIEW Front Panel

• All user interfaces goes here!

• Used to display Controls or Indicators

• Highly customizable

Page 57: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

LabVIEW Block Diagram

• Actual program

• Invisible to user

• Read left to right, like a book

• Where the MAGIC happens!

Page 58: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

TerminalsWhen you place a control

(or indicator) on the

FRONT PANEL

LabVIEW automatically

creates a corresponding

control (or indicator) terminal on the BLOCKDIAGRAM

Page 59: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Control? or Indicator?

Controls = Inputs from the user = Source Terminals

Indicators = Outputs to the user = Destinations

Page 60: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Manipulating Controls and Indicators

• Right click on an indicator to– Change to control– Change format or precision

• Right click on a control to– Change to indicator– Change mechanical action (whether to latch open

or closed, and what to use as default…)

Page 61: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Wiring Connections• Wires transport data through the block diagram

• Wire color indicates variable type

• A red “X” means something is wrong!

Page 62: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Wires

A LabVIEW VI is held together by wires connecting nodes and terminals; they deliver data from one source terminal to one or more destination terminals.

Page 63: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Basic wires used in block diagramsand corresponding types

Each wire has different style or color, depending on the data type that flows through the wire:

Scalar 1D array 2D array Color

Floating-point number

orange

Integer number blue

Boolean green

String pink

Page 64: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Dataflow Programming

• In this case, the block diagram executes from left to right, not because the objects are placed in that order, but because the Subtract function cannot execute until the Add function finishes executing and passes the data to the Subtract function. Remember that a node executes only when data are available at all of its input terminals and supplies data to the output terminals only when the node finishes execution.

Page 65: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Data Flow programming (Contd)

• consider which code segment would execute first—the Add, Random Number, or Divide function. You cannot know because inputs to the Add and Divide functions are available at the same time, and the Random Number function has no inputs.

Page 66: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Running LabVIEW Programs

• ALMOST ALWAYS put your program in some sort of loop that can be stopped with a control

• AVOID using the red “x” to stop your program

Page 67: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Add/edit text

Wire features together tocontrol flow of data

Select a feature toedit or move

Operate a control

Probe Data(troubleshoot)

Page 68: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Insert a digital indicator or control

Insert a boolean control (button or switch)

Page 69: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Add a structure such as for, while, and case statements

Add a numericoperator (+,-,…)

File I/O

Add a booleanoperator (and, or…)

Data Acquisition

Signal analysis

Comparison

Mathematical Functions

Timing/dialog

Page 70: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Reorder objects

Run

Continuous run

PauseStop

Font ring

Alignment ring

Distribution ring

Debugging featuresmore on this later…

Page 71: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Examples

• Area of a triangle.• Print “Hello World”.• Connecting different data types (if time

permits)

Page 72: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

What is MyDAQ• General Purpose Data Acquisition Device• Multimeter, Oscillocope, Function Generator, • Spectrometer and much more

=

+

+

$50-$200

$300-$10,000

$300-$5,000

$200

+ much more

Page 73: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

• MyDAQ - Designed for hands-on experimentation. NI MyDAQ combines portability with a comprehensive set of features. NI MyDAQ allows for real engineering and, when combined with NI LabView and Multisim, gives students the power to prototype systems and analyze circuits in or outside of the classroom.

• NI MyDAQ hardware integrates with NI Labview graphical development software, giving the students hands-on interaction with real analogue circuits, sensor measurements, and signal processing. It bridges the gap between theory and real-world practice by providing students with eight Labview software-based instruments including a digital multimeter (DMM), oscilloscope, function generator, bode analyzer, dynamic signal analyzer, arbitrary waveform generator, digital reader and digital writer.

• NI MyDAQ is compact enough to fit in a student's pocket, and is powered by a USB connection.

Page 74: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh
Page 75: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Digital Multimeter (DMM)

Page 76: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Measuring Resistance Across 1000Ω

Page 77: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Examples

• Read 5 volts from analog input using a wire.

Page 78: EE4314 Lab 1 Session Matlab and Simulink Spring 2014 TA: Joe Sanford joe.sanford@mavs.uta.edu joe.sanford@mavs.uta.edu (with special thanks to Suresh

Questions?