You are on page 1of 111

ECE 595K/ECE 495A LabVIEW

Credits: 3(Class 2, Lab 3)


Prerequisite: ECE 595K Graduate Standing
ECE 495A Junior or Senior Standing

Richard Gonzales
Ofc P323, Ofc hrs: I am at PU all day TU & TR in my Ofc or a Lab
Email: RichardGonzales@aol.com

Course Description: Theory and application of the graphical


programming language LabVIEW in Data Acquisition, Control, Design,
Analysis, Synthesis, Simulation, Instrumentation, and Engineering Problem
Solutions: LabVIEW will also be used as a general purpose language to
dot asks that have traditionally been done by languages such as C,
MATLAB, SIMULINK, and EXCEL.

Lab 3 hrs per week, Lecture 2 hrs per week


Tu & Th 11:00 to 1:20 in P308..

1
Reference Texts:
Labview 8 Student Edition, Robert Bishop, Prentice Hall, 2007
LabVIEW for Everyone, Travis & Kring, Prentice Hall, 2008
Introduction to Data Acquisition with LabVIEW, King, McGraw Hill, 2009
Labview Graphical Programming, Johnson & Jennings, McGraw Hill, 2006
The LabVIEW Style Book, Blumb, McGraw Hill, 2007

Course Grading:
This is a relatively new experimental course, and the course grading and
content may need to be modified as the course is developed. The current
thinking is shown below. You will be kept informed of any changes
implemented.

Tests & Quizzes .......................................25%


Homework Exercises ...............................25%
Laboratory Performance & Attendance....25%
Project and/or Final Exam........................25%

2
LabVIEW
Laboratory Virtual Instrument Engineering Workbench
Another and better name
Graphical Programming Language G (not text based)
It is a general purpose language like C, MATLAB, and others
It has Instrumentation and Display Capability
It is used for Simulation
It is used for Data Acquisition
It is used in Control Applications

Programs are called Virtual Instruments, VI’s


File names example: prog1.vi, xyz.vi, etc. The extension is vi
3
Temperature Demo.vi
Load from Demos Folder, Run and Discuss

Front Panel,
Block Diagram
CTRL T toggle
Icon/Connector

Look at menus navigation, etc

Start LabVIEW and open a new vi

Visible pallet sets


1. Left click on Front Panel to get Controls Palette
2. Pin either the Classic or Modern Controls Palette
3. Left click on the Diagram Window to get the Functions Palette
4. Pin the Programming Palette
5. To get the Tools Palette click on View-Tools Palette
4
6. Look at different possible views of controls and Functions Palette
Temperature Demo.vi cont

• Left click on icons and others - look at menus

• Run the program - discuss results

• Blue integers, orange floating point

• Try different inputs (Control values)

• CTRL H Context Help

• Nodes - program execution elements, Add, Subtract, subprograms.

• Wires - data paths

• Controls = Inputs

• Indicators = Outputs
5
Data Flow Programming.

A node can executed only when all the input data arrives at its
input terminals. The node supplies data to all of its output
terminals when it finishes executing.

In contrast text based programs execute in the sequence they


are written.

Load Arith-2.vi
Highlight execution and step through to demonstrate the data
Flow.

6
Students Create some vi’s

3. Create a new vi Arith.vi


Controls - numerical inputs A, B, and C
Indicators - numerical Outputs Out 1, and Out 2
OUT1 = A + B
OUT2 = (A+B) - B/C
Build the vi shown below.

7
Students Create some vi’s cont

3. Create Arith-2.vi
Add a Boolean light to Arith.vi
The light should go on if A > to 3, and is otherwise off

8
By convention, where possible, the data flow programming
diagrams are constructed so that the flow is left to right.
This results in the best readability.
Note: Nodes also generally have their inputs on the left and outputs on the right.

Arith-2.vi Arith-2Poor.vi – Poorly done. Load,


highlight execution, and run it

9
Random number generation

Rand #.vi
open and discuss
Case.vi
open and discuss
Students Create some vi’s cont

1. Create Arith+Case.vi
Add a True False Case to Arith-2.vi such that if A is not = 0 then
calculation is as before, but if A = 0 then OUT 1 = a random number
between -5 and +6.8 (Span=11.8), and OUT 2 is unchanged.
Short list LabVIEW Shortcuts and some Notes

Ctrl+H Opens Context Help Window


Ctrl+E Toggle between Front Panel and Block Diagram
Ctrl+B Remove Broken Wires
Ctrl+Z Undo button
Ctrl+R Run VI
Ctrl+F Find Object
Ctrl+W Close Active Window
Ctrl+T Tiles the Front panel and Block Diagram

Ctrl Hold down after selecting object and drag away to make a copy of
object Hold down while making a box in whitespace to make
more room
Shift Hold down while using arrow keys to move an object faster
Hold down and right click mouse button to bring up Tools Palette
Right-Click On any input or output to make controls/constants or
indicators. On any control and go to Replace to change to
another type, and go to Properties to modify a specific item
13
Short list LabVIEW Shortcuts and some Notes – cont

Tools —> Options Set Preferences in Labview

Instrument Drivers
Drivers available at ni.com/idnet
Install the instrument driver VI Library into LabVIEW 8.0\instr.lib
directory. Access drivers from

Functions»Input»Instrument Drivers subpalette

NI Technical Support www.ni.com/support 1-866-275-6964

Drivers and Updates www.ni.com


Creating SubVIs (Subroutines)

Any vi can be made into a SubVI just like any routine (program) can be
Made into a subroutine.

Method 1
Arith.vi
Open and discuss

To make Arith.vi into a SubVI, and give it a new name ArtihS.vi


Load Arith.vi
Edit the Icon to identify the SubVI as ArithS
Option – rename Controls and Indicators if desired
Select the desired Connector (3 input, 2 output)
Wire desired Controls and Indicators to the Connector
Save the result as ArithS.vi

Note: I think that it is usually best use the


SubVI’s name for the SubVI Icon.
Creating SubVIs (subroutines) cont.

Method 2
Open Arith+Case.vi

Select the same code that generates the SubVI ArithS.vi

Use Menu EDIT-Create SubVI to create the SubVI .


Open the SubVI and edit the Icon as desired - ArithS.
Rename the Controls and Indicators as desired.
Save the result with the desired name – in this case ArithS.vi
SubVIs cont.

Using SubVIs in a program.


A SubVI can be used as many times as desired In a program.

Demonstrate using the SubVI ArithS.vi 2 times in a program named


UsingSubVI.vi where the 2 sets of inputs and outputs for the 2 SubVIs
are::

Set 1. Inputs: A=X a control, B=3 a constant, and C=6 a constant.


Outputs: Out1=Z an indicator and Out2=Out2 an indicator

Set 2. Inputs: A=6 a constant l, B=X a control, and C=Z the output
from Set 1.
Outputs: Out1=XX an indicator and Out2 not used

Note: Load UsingSubVIIO.vi which contains the Controls, and Indicators


as a starting point for the VI.
Important! - Programming Success
• A Step at a Time Build programs and
subprogram in small steps testing each step
thoroughly before adding the next step. Don’t go
for broke with a big program!!
• Divide and Conquer. Use Modular
Programming techniques with SubVIs and
Subprograms
LabVIEW Exercises
2. Write a VI to calculate the function: y = b^2-4*a*c

Make this VI into a SubVI Disc.vi with an appropriate icon and icon
connect Inputs (controls) are a, b, and c,. The output (indicator) is y.

a
b Disc y
c
2. Write a SubVI that calculated the roots of a quadratic equation using
the SubVI disc.vi from Exercise 1. The digital inputs to the VI should
be the quadratic equation coefficients, and the outputs the roots of the
quadratic equation. Note that the VI should be capable of dealing with
both real and complex roots of the quadratic equation. Make this VI
into a SubVI quad eq.vi with inputs a, b, and c, and outputs r1, i1, r2,
and i2.
a r1
i1
b quad eq
r2
c i2 19
quad.vi - logic

Calculate Disc

R1=(-b+sqrt(Disc))/(2*a)
YES I1=0
Positive?
R2 =(-b-sqrt(Disc))/(2*a)
I2=0

NO

R1=-b/(2*a)
I1=+sqrt(-Disc)/(2*a)
R2=-b/(2*a)
I2=-sqrt(-Disc))/(2*a)
Assignment due next period. Hand in: Exercise 2
Exercise 2 on a 3 ½ floppy disk Open and discuss

File Folder name Exercise 2


Contents: Quadratic roots
Exercise 2.vi (-b+sqr(b^2 -
Disc.vi 4*a*c)/(2*a)
quad eq.vi (-b- sqr(b^2 -
+ anything else needed 4*a*c)/(2*a)
VI Examples
Learning LV8 examples from our text book in a Folder on the
G drive
Demos Folder
ni.com web site
See Examples choice on LabVIEW welcome screen
Lots of other examples on line, and in many textbooks

22
Trouble shooting
Use quad eq.vi with its SubVI disc.vi to show some trouble
shooting techniques
1. Show how to set default values on A, B, C (Say 1,2,3 or
other)
2. Highlight Execution – run and look at data flow
3. Step thru the program
3. Show use of the Probe
4. Use the Stop to execute up to a point and then step thru.

23
Case Structures For more than just T, F case

demo Cases-3.vi
Connect a numeric control to the boolean input, and instead of
True False it becomes 0,1 then add as many cases as you
want

Add other cases. There are 3 total in the Demo see be,low

24
While Loops
Open & Demo
WhileLoop.vi

Build a piece at a time


While - both with Stop if True & then change to Continue if True
Always executed once. Check for stop/continue is done after the loop
execution.
add random #
add indicators inside and outside loop
add indexing and explain
add array indicator
25
While Loops with Shift Registers
Demo ShiftReg1.vi,
Add initilization of the
Shift register

Demo ShiftReg2.vi Sumation of i


Step thru and show results

26
Demo ShiftReg3.vi
Add feedback registers
I
i-1
i-2
etc

27
Demo x^i.vi

Step thru and show results


Exercise 3. Write a SubVI e^x.vi to generate the function e^x
, where x is a digital input, and e^x is a digital output. Use a
Taylor series to generate the function
with accuracy up to the nth place.

Taylor Series e^x = 1 +x^1/1! + x^2/2! + x^3/3! +x^4/4! +…

For example if n=5 the series should use terms up to and


including the first one that is less than .00001 in absolute value).
The SubVI should also output the value of y and the number of
terms used.

The SubVI should output the value of e^x and the number of
terms in the series.
29
Exercise 3 cont.
Test your SubVI e^x.vi with Test e^x.vi - demo it.

30
Important! - Programming Success
• A Step at a Time Build programs and
subprogram in small steps testing each step
thoroughly before adding the next step. Don’t go
for broke with a big program!!
• Divide and Conquer. Use Modular
Programming techniques with SubVIs and
Subprograms

Load and demo Step at a Time with Exercise 3 - s1, s2, s3


Exercise 4. Write a SubVI Sin(x).vi to generate the function
Sin(x) , where x is a digital input. Use a Taylor series to
generate the function with accuracy up to the nth place.

Taylor Series Sin(x) = x - x^3/3! + x^5/5! - x^7/7! +…

For example if n=5 the series should use terms up to and


including the first one that is less than the absolute value of
.00001.

Write a test VI, TestSin(x).vi to test your Sin(x) SubVI.

32
Introduction to Graphing
Waveform Chart:
Open & Demo Charts.vi
Strip chart
Scope Chart
Sweep Chart

Exercise 5. Modify the above vi to display the SubVI Sin(x).vi of


Homework Exercise 4 on a waveform chart. Let the value of X take on
the values of the loop index I, and experiment with various delay values.
33
Demo Charts-1.vi
Adding chart signals. Replace the Bundle with a Build Array and note the
difference.

Bundle yields two separate traces


Build Array yields one trace, the sum of the two traces, because new
data is appended to old

Stop

34
Waveform Graphs Build below a step at a time
Graphs-1.vi

Build array - note array sizes expanded with zeros to make both the same

35
Graphs with time. Graphs-2.vi

36
XY Graph XY Graph.vi. Inputs are X arrays & Y arrays

Delete pieces from XY Graph.vi and build back up in pieces in pieces


Introduce Express vi’s
Build Express XY Graph is found on the Modern Graph Pallet
Dynamic data
Add cursor and make cursor free, use finger to move it around, and
examine values on the curves

37
Exercise 6
Generate 100 random numbers in the range from +1 to -2, one number
every 0.1 seconds. Also generate 100 values of 1.8sin10t, one value
ot t every 0.1 seconds, ie, 0, .1, .2, .3 …
c) Display both the random numbers and the 1.8sin10t numbers on a
single Waveform Chart as they are being generated, and experiment
with the different display options and features. The objective is to learn
all about Waveform Chart properties and features
d) Generate the above numbers and collect them in arrays. Display the
arrays on a Waveform Graph verses the array index. Also display the
arrays on a Waveform Graph verses time. Experiment with the
different display options and features. The objective is to learn all
about Waveform Graph properties and features
e) Display the array for the random numbers on the X axis, and the sin
wave array on the y axis of an XY Graph. Experiment with the different
display options and features. The objective is to learn all about
XYGraph properties and features
38
Formula Node Formula Node-1.vi

If else example
Note lower case if and else

39
Formula Node while loop example Formula Node-2.vi

40
Formula Node For Loop example Formula Node-3.vi
;

41
Some Formula Node Syntax Formula Node-4.vi
floating-point-type:float, float32, float64
integer-type: Int, int8, int16, int32, uInt8, uInt16, uInt32
assignment-operators: = += –= *= /= >>= <<= &= ^= |= %= **=
binary-operators: + – * / ^ != == > < >= <= && || & | % **

Formula Node with Arrays example Formula Node-4.vi


Note i++ is short hand for i=i+1

42
Formula Node
Do loop
1 1 1 1 1 1 1 0 0 0 0 0 0
Formula Node-5.vi 4 2 2 2 0 0 1 1 1
4 1 1 1
Bubble sort 2 2 4 0 0 2 2 2 2 2 2 2 2
0 0 0 4 4 4 4 4 4 4 4 4 4

43
Exercise 7
Write a SubVI Roots.vi using a Formula Node to calculate the roots of
a quadratic equation Ax^2+Bx+C.

A R1
B Roots I1
C R2

I2

This, of course, should yield the same result of the earlier SubVI
quad.vi.

44
Arrays
Build Array, Array Size
Array-1.vi

Index Array
Array-2.vi

45
Replace Array Subset: Array-3.vi
Array in determines size of the Array Result

Insert Into Array: Array-4.vi

46
Initialize Array, Array-5.vi

Examine all the other array operations in the Programming pallet

Exercise 8 Create a good example for one of the other array and
email it to me at RichardGonzales@aol.com. I will then email all of
the examples back to everyone.

47
Polymorphism – dealing with arithmetic operations on arrays of different
dimensions

Polymorphism.vi

48
Indexing (again) with For and While Loops – Demo Indexing Loops.vi
Clusters: Creating Clusters for either indicators or controls
The order (not the position) placed in the Cluster shell determined the
order in the cluster.

Demo Clusters.vi

50
Local Variable
A local variable can be
created for any control or
indicator.

Demo the Kitchen Timer.vi

Exercise 9 Note the problem


with the Kitchen Timer:
It can not be reset after it
starts running. Fix this
problem. Use the name
Kitchen Timer-2.vi. Another
local variable may prove
useful.

51
Exercise 10 Write a bubble sort sub vi: Sort-B.vi. that does the same sort as
Formula Node-5.vi, but does not use the formula node and C code. LabVIEW
For loops, While loops and other structures should be used. You may find that
the use of a Local Variable will prove useful in order to set a DONE condition, and
then to read, and to act on that condition.

Input Array Sorted Array


[x] Sort-B [y]

1 1 1 1 1 1 1 0 0 0 0 0 0
4 4 2 2 2 0 0 1 1 1 1 1 1
2 2 4 0 0 2 2 2 2 2 2 2 2
0 0 0 4 4 4 4 4 4 4 4 4 4

52
Exercise 10 cont Write a bubble sort sub vi: XY Sort-B.vi. that will sort [X], [Y]
data pairs so that they are ordered pairs for increasing values of X. Test your
SubVI with the [X], [Y] data pairs below:

[X] = 3.9 [Y] = -4.9 Sorted [X] = -3.1 Sorted [Y] = -1.9
12.6 6
6.3 4 2.1
0 6.7 -1.2 6.7
-3.1 -1.9 0 3.1
10.1 -1.5 1.2 -4.9
5,0 -8.1 3.9 -8.1
7.5 1.9 5,0 4
2.1 6.3 1.9
-1.2 3.1 7.5 -1.5
10.1 6
1.2 12.6
[X] Sorted [X]
XY
[Y] Sort-B Sorted [Y]

53
Trapezoidal Integration lecture etc. on black board
y

A2 yi+1
Ai x yi
A0 A1

Ai

xi xi+1

x0, x1, x2, x3, ………… Ai = ((yi+1+ yi)/2)*(xi+1 + xi)


y0, y1, y2 ………
Etc

54
Exercise 11 Write a SubVI (Trap I.vi) that will integrate a curve y(x)
using trapezoidal integration. y(x) is described by [x], [y] data
points, two arrays. The integral array [z] is the output of the SubVI,
and is an array of values for the integral.

[x]
Trap I [z]
[y]

Write a test routine Exercise 11.vi to test the SubVI by integrating the
curve described by the following data points.

(x,y) = (-3.1,-1.05), (-1.2,-2.51), (0,-3), (1.2,-2.91), (3,-2.43).


(5,0), (6.3,2.42), (7.52,3.80), (10.1,4.67), (12.6,3.78),
(14,2.78), (14.92,1.75), (16,1.30), (19.7,-.99), (21.5,-2.03)

Graph both y and z as a function of x on the same graph.

55
Exercise 11.vi, testing the Trap I SubVI

56
Interpolation Lecture summary
Ya Yi+1
Y Ya
Yi

X0
X
XL Xi Xa Xi+1
Xa

Xa is in the range X0 to XL
Ya = Yi+1 – Yi)/(Xi+1-Xi)) (Xa-Xi) + Yi
Point slope formula Y = mX + B
[X] = X0, X1, X2, x3, …XL
[Y] = Y0, Y1, Y2 ……… YL

57
Interpolation Lecture summary Xa, Ya
Out of range Xa<X0 or Xa>XL

XL, YL

X0, Y0 Xa>XL
Ya = (YL - YL-1)/(XL - XL-1)*(Xa-XL) + YL
Xa, Ya
Xa<X0
Ya = (Y0+1 - Y0)/(X0+1 – X0)*(Xa-X0) + Y0

[X] = X0, X1, X2, x3, …XL


[Y] = Y0, Y1, Y2 ……… YL

58
Exercise 12
Write a SubVI Interp.vi that does linear interpolation for array data points [X], [Y]. That
is, for an input Xa the output Ya will be calculated, Outside of data range interpolation
should take place, and the out of range magnitude M calculated and printed. The vi
should also output the value of the index i, where Xi<=Xa<Xi+1. Note if Xa<=X0 the
value of i should be 0, and if Xa>=XL the value of i is L-1

[X] Ya

[Y] Interp i
m
Xa

DemoTextInterp.vi

59
DemoTextInterp.vi
Exercise 12 cont. Write a SubVI InterpM.vi that does linear interpolation for a array of
data [X], [Y] points, and for an array of input values [Xa]. That is, interpolation for the
elements of an input array [Xa] an interpolated output array [Ya] will be calculated.
Also an array [i], and an out of range magnitude array [m.] will be calculated.

X] [Ya]

[Y] InterpM [i]


[m]
[Xa]

Write a vi, Exercise 12.vi, to test InterpM.vi and Interp.vi using the [x], [y] data of
Exercise 11, and the following test values for [xa].

[Xa] = [-5, -3.1 -2.03, -1.49, 6.3, 9.8, 11.5, 17.62, 19.7, 21.5, and 23.4].
Test other data array inputs.

61
Exercise 12 – Demo TestInterp&InterpM.vi,
Select 1.vi
A 3 bit binary array selector
Select 2.vi another selector

Select 2.vi

64
Integration from xa to xb, lecture etc on blackboard, Calculate the Integral of a curve
from xa to xb using original data where possible.
y

A2
xa Ai Ai+1

A0 A1
x
xb

Note xa and xb are not required to be data points.


Given, xa, xb, and
x0, x1, x2, x3, …………
y0, y1, y2 ………

65
Exercise 13
Write a SubVI NewD.vi with inputs [x], [y], xa, and xb. The outputs of the SubVI are
modified arrays [xn], and [yn], which are new set of data point arrays from the low
limit xa to the high limit xb. The original data points are to be used except at the end
points xa and xb. Thus, interpolation will be necessary and your sub vi Interp.vi will
be needed. Also consider error checking for invalid input values etc.

[x]
[xn] = [xa, xi, xi+1, …., xb]
[y] NewD
xa [yn]
error
xb

Write a vi TestNewD.vi that calculates an array [z] which is equal to the integral
of a curve defined by arrays [xn] and [yn] above. TestNewD.vi logically will thus
include the SubVIs Trap I.vi, NewD.vi, and Interp.vi. The integral is to be from a
low limit of xa to a high limit of xb. The output results [z], vs the [xn] should be
graphed over the range from xa to xb. Use the data of Exercise 11, and test
your vi for xa = -4.9, xb = 11.5, and xa = 3.1, xb = 10.5. Also test for other alues
for xa &, xb. Check the results to make sure the vi is working properly.
66
TestNewD.vi. Run it also for for various values of xa, and xb

67
Integration from Xa to Xb using new points equally spaced, Calculate the Integral of
a curve from Xa to Xb using new points equally spaced by inc.
y

A2
xa

A0
x
xb

Note xa and xb are not necessarly data points.


Given, Xa, Xb, and inc, the desired increment, and data
x0, x1, x2, x3, …………
y0, y1, y2 ………
calculate [xn] = [xa, xa + inc, xa + 2*inc +…………..xb] etc Black board lecture
68
Exercise 14
Write a SubVI NewD2.vi with inputs [x], [y], Xa, and Xb. The outputs of the SubVI
are modified arrays [Xn], and [Yn], which are new set of data point arrays equally
spaced by inc from the low limit Xa to Xi<=Xb. That is [Xn]=[Xa, Xa+inc, Xa+2*inc,
….Xb] Thus, interpolation will be necessary. Also consider error checking.

[x]
[Xn]
[y]
xa NewD2 [Yn]
xb error
inc

Write a vi Exercise 14.vi that calculates an array [z] which is equal to the integral
of a curve defined by arrays [x] and [y]. Exercise 13.vi logically will include the
SubVIs Trap I.vi, NewD.vi, and Interp.vi and possibly InterpM.vi. The integral is
to be from a low limit of xa to a high limit of xb. The output results [z], vs the [xn]
should be graphed over the range from xa to xb. Use the data of Exercise 11,
and test your vi for xa = -4.9, xb = 11.5, and inc =1, and for xa = 3.1 and xb =
10.5, and inc=1 and also test it for other values for xa &, xb. Check the results to
make sure the vi is working properly. 69
Demo SubVI, xa inc xb.vi:
given [x] xa, inc, & xb, create [xa, xa+inc, xa+2*inc………xb ]
TestNewD2.vi: Testing NewD2.vi

71
Curve Fitting,
Blackboard lecture first on polynomial curve fitting then:

Demo CurveFit-1.vi, and CurveFit-2.vi & use experiment with different polynomial
Orders.

72
Curve fit with lots of points: Demo CurveFit-3.vi, with different orders
from demo folder

73
Blackboard Lecture on polynomial Integration

74
Exercise 15, Polynomial Integration
Write a SubVI to evaluate the integral of a polynomial c0 + c1*x =+ c2x^2 + …
Start by writing the SubVI PolyInt 1 Point.vi with input data [c (poly coef)], and x to
do the evaluation of the integrated polynomial c0*x/1 + c1*x^2/2 + c2* x^3/3 +
c3*x^4/4 + … ……… The output of the SubVI z is the integrted polynomial
evaluated at one value of x (1 point).

Then write PolyInt.vi with array data inputs [c (poly coef)], xa, inc, and xb. The
output of the SubVI is the integral array, [z]. [z] is the integral from xa to xb
evaluated at each [x2] array point, where [x2]=[xa, xa+inc, xa+2*inc, xa + 3*inc,…. …
xb]. This routine will logically use the SubVI PolyInt 1 Point.vi.

[c (poly coef)] z [c (poly coef)] [z]


PolyInt xa PolyInt [x2]
1 Point inc
x error error
xb

Write a vi Exercise 15.vi to test PolyInt.vi, PolyInt 1 Point.vi and calculate the array
[z], which is equal to the integral at the data points [x2] of a curve defined by arrays
[x] and [y]. Plot the results and fully test the vi’s. Use the data of Exercise 11, and test
your vi for xa = -4.9, xb = 11.5, and inc =1, and for xa = 3.1 and xb = 10.5, and inc=1
and also test it for other values for xa &, xb. Experiment with different polynomial75 fit
order. Check the results to make sure the vi is working properly.
Exercise 15, Polynomial Integration test results
Demonstrate this vi

76
Submit your Exercises on 3.5 floppy disk

1. Print your name on the outside of the 3.5 floppy.

• Submit all completed exercises. Save complete folders with all SubVIs needed
for each exercise in the folder, eg, Exercise 1 Folder, etc.

Lecture on Least square error curve fitting - Regression


Hand out & discuss Regression.doc
Linear Algebraic Equations
Demo Lin Alg.vi.

78
Exercise 16,
Write a SubVI Poly LSE Fit.vi to determine the polynomial coefficients for a least
square error fit of data points [x], [y] using the regression technique. This SubVI
should be basically the same as the LabVIEW LSE routine

[x] [y] Best fit


Poly [c (poly coef)]
[y] LSE
mse
Fit
Order error

Write a vi, Exercise 16.vi, to test Poly LSE Fit.vi. Use the [x], [y] data of Exercise 11,
and compare your results with the LabVIEW LSE routine, and Check the to make
sure the vi is working properly.

79
Exercise 16.vi
Course Project, Paper, and Presentation

A few Project Ideas


Data Acquisition
Gauss Jordan linear equation solver
Fast Fourier Transform
Serial Communications
Active X
GPIB
Instrument Control
Property Nodes
Event-Driven Programming
Report Generation
Signal Generation
Signal analysis
Signal Processing
MathScript
Master Slave loop techniques
Internet resources and examples
I/O file handling
Digital Filtering
Digital image processing
Video image processing
3 dimension graphing
Event handling – mouse & keyboard
Anything that contributes new knowledge, examples & etc.

81
Schedule
Project Selection Due November 4 with a brief written abstract of what you plan to do.

Final Project Abstract and all Exercises are Due November 20 on your 3.5 disk
Final Abstract Format
Title:_____________
Name:____________
Brief description less than 100 words

Project Paper And Programs Are Due November 25


Put everything on your disk in a folder named PROJECT and give it to me on 11/25.
In addition give me a printed copy of the project paper.

Project Oral Presentations


November 25 Wajahat Asfar
Hui Wang
Guoheng Chen

December 2 Ning Xu
Xiao Guo

December 4 Xiaohan Xu
Man Xu

82
Euhlers Technique, Differential Equations

Blackboard lecture on first order differential equationse

83
DE Euh 1.vi, demo this

F(X,Y) Euh 1.vi

84
Blackboard lecture and hand outs on Euhler’s technique for an nth order differential
equations.

Exercise 17,
Write a SubVI Euh M.vi that uses Euhler’s method to solve a set of 1st order
differential equations. Note, also a SubVI F(X,Y) Euh M.vi will be needed for the
function describing the differential equation

X0
[X] X
DX F(X,Y) [F(X,[Y])]
Xl Euh M Euh M
[Y] Y
[Y]0

Write a VI, TestEuh M.vi, to test Euh,M.vi, and F(X,Y) Euh M.vi for the differential
equation Y’’’ + 5Y’’ + 8Y’+6Y= 3. Check the to make sure the VI is working properly.

85
Exercise 17.vi, demo this.

86
Exercise 18
The Rocket
air drag
K(y)*dy/dt*|dy/dt|lbs
This is a hypothetical
LabVIEW Design Exercise.
A weather and pollution data
gathering rocket containing
delicate instrumentation and mass of rocket with a
full load of fuel at
photographic equipment is t=0 is 9.56 slugs
y(t)
being developed. The (weight = 307.8 lbs)

rocket, using a solid rocket


fuel, is to be launched from
the ground. It is expected
to reach an altitude of
force of gravity engine thrust in lbs
about 1 mile, and then m(t)g lbs, where T = -156*dw(t)/dt,
g = 32.2 ft/sec2
return to earth under the where w it the
fuel weight lbs
influence of gravity. A
free body diagram showing
the forces acting on the
rocket is shown.

87
As fuel is burned a thrust force is created which is
proportional to the rate of fuel consumption. Laboratory
data from dynamometer tests shows the rate of fuel
consumption Vs time. Data points are provided showing
consumption in lbs per second Vs time for the 9 second
solid fuel burn cycle in the file -DWDT.VI.

The air friction function K(y) varies with altitude. As


altitude increases the air gets thinner and the friction
multiplying factor decreases. The data file K(y)Data.vi is
provided.

As fuel burns the rocket mass decreases. This and the


nonlinear drag force result in a nonlinear system of
differential equations which do not lend themselves to
analytical solution, and thus a numerical digital solution
may be the only way to investigate this design problem.
Various simplifying assumptions have been made, such as a
constant gravitational force and the air density force
function. An analysis of the free body diagram follows:

88
Note that for t > 9 seconds m’ = 0, T = 0.

Applying Newton’s Laws for the free body diagram yields:


d(mv)/dt = T - 32.2m – K(y)dy/dt|dy/dt|

note that d(mv)dt = mdv/dt + vdm/dt

and since v = dy/dt thus,

md2y/dt2 + dy/dt*dm/dt = T - 32.2m – K(y)dy/dt|dy/dt|,

or

d2y/dt2 = 1/m(T - 32.2m – K(y)dy/dt|dy/dt| - dy/dt*dm/dt)

This equation is now converted to a set of 1st order


differential equations.

letting Y0 = y, and Y1 = dy/dt and using prime (‘) to denote


differentiation (d/dt) yields the following state equations:

Y0’= F0 = Y1
Y1’= F1 = (T - 32.2m – K(Y0)Y1|Y1| - m’Y1)/m
Analyze and investigate the rocket flight using LabVIEW.
Your solution should include the following:

• Data points and a graph of the position (y),


velocity (y’), and acceleration (y’’) Vs time.
• Determine the time and magnitude of the maximum
height, velocity and acceleration of the rocket.
3. How fast is it traveling when it hits the ground?
4. What is the average velocity for the entire flight?
5. How long is the flight from the time it leaves the
ground until it returns.

You will need to include a provision at launch time so


that the height of the rocket does not go negative
(below the earth), because at t=0, and until some time
t1 the solid fuel thrust force is less than the force of
gravity. This will accelerate the rocket in the -y
direction. In reality the launch pad would prevent this
from happening.
90
Your solution should be modular with appropriate SubVIs. For
the SubVI F(X,Y) Euh M.vi the following two vis will be needed.

m Rocket
Time Data Mass Slugs
Fuel Rate Data m’ rate of change Rocket mass
mm’T
slugs/sec
Time
T Rocket EngineThrust

y K(y) K(y)

Interpolation and trapezoidal integration are appropriate for the fuel data
to calculate m, m’ and T. For the air friction function K(y), a polynomial
curve fit is preferred because of the nature of the data given. 91
Logical extensions to this design problem are:

1. Jettison the fuel section of the rocket after the fuel is used up. This would
reduce the mass and effect the final altitude, and/or amount of fuel required.
Say that the fuel shell that can be discarded is 1 slug, and it could be
jettisoned 1 second after the fuel is used up.

2. The use of a parachute to be deployed at a prescribed altitude in order to


soften the landing, and protect the payload. The parachute could create an
additional air drag force that would increase with time during deployment from
0 to a maximum value of kp*dy/dt*|dy/dt|. Maybe a reasonable deployment
algorithm might be linear increase in kp from 0 to .0876 in 1 second.

3. The effects (max velocity, acceleration, height etc,) resulting from different
solid fuel burning rate schedules with the same initial amount fuel.

9. Investigate the effects of gravitational changes that occur with altitude.

Do a demo of the Solution Exercise 18

92
File I/O and Strings Demo these

File I/O 1.vi


Create Path, and write time &
Date to a Text File

File I/O 2.vi


Create a file with time date
as file name & write a numerical
Value converted to ASCII to the file

93
File I/O 3.vi:
File Path, Headers, Write to a Text File,
Write to a Excel File, and Write to a a
binary File
Data Acquisition DAQ
Demo this

94
File I/O 4.vi:
Read 1d String Data from a Text File
and convert to Numerical 1d Data
Array. Data Acquisition DAQ - Demo
this

95
File I/O 5.vi:
Read Data from a Binary File and convert to Numerical 2d
Array Data. Data Acquisition DAQ - Demo this

96
Exercise 19
Study File IO 1.vi, File IO 2.vi, File IO 3.vi, File IO 4.vi, and File IO 5.vi …. for a
full understanding.
Write a SubVI String to Numbers.vi that will convert multiple lines of an ascii
string of numbers to a numerical array. The vi should handle String data
representing by both 1 and 2 dimensional data. The data string format is tab
separated for each row, and rows are separated by a carriage return. Fully test
the SubVI with Exercise 19.vi – Sample below.

Array 1d
String
String
to
Numbers Array 2d

97
DAQ1.vi Demo
Data acquisition, analog in using DAQ Assistant, 1 Sample, 8 Channels, on Demand,
10 ms loop time = acquire rate, Channel 2 Selected for acquired samples and
graphing

98
DAQ2.vi Demo
Data acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels,
at 10HZ (10 ms sample rate), Channel 2 Selected for acquired samples and graphing

99
DAQ3.vi Demo
Data acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels,
at 10HZ (10 ms sample rate) , Time & channel results saved in an EXCEL spread
sheet and graphed.

100
DAQ4.vi Demo
Data acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels,
at 10HZ (10 ms sample rate) , time added to data, results saved every .1 sec as it is
acquired in a text file.

101
DAQ5.vi Demo Data acquisition
Digital Input
Digital Output
Analog Out - DAC

102
Data Buffer Window.vi Demo
Array In has new Add Array appended to it array resized, and oldest data is discarded
yielding Array OUT – a moving window

1 2 3 4 5 6 7 8 9 10

103
DAQ6.vi Demo Master – Slave
Analog in DAQ

104
DAQ Signals.vi Demo A DAQ Signal simulator for 5 channels with sin, square wave,
and random signals of variable frequency, amplitude and offset

Time
Input
FFT.vi Demo Fast Fourier Transform
Demo vis in Mouse Examples Folder

107
108
109
110
111

You might also like