Lab 2: Getting Familiar With Labview: Part Ii: L2.1 Building A System Vi With Express Vis
Lab 2: Getting Familiar With Labview: Part Ii: L2.1 Building A System Vi With Express Vis
Lab 2: Getting Familiar With Labview: Part Ii: L2.1 Building A System Vi With Express Vis
LabVIEW: Part II
Now that an initial familiarity with the LabVIEW programming environment has
been acquired in Lab 1, this second lab covers an example where a simple DSP
system is built, thus enhancing the familiarity of the reader with LabVIEW. This
example involves a signal generation and amplification system. The shape of the
input signal (sine, square, triangle, or saw tooth) as well as its frequency and gain are
altered by using appropriate FP controls.
The system is built with Express VIs first, then the same system is built with
regular VIs. This is done in order to illustrate the advantages and disadvantages of
Express VIs versus regular VIs for building a system.
Figure 2-33: BD of signal generation and amplification system using Express VIs [1].
one wire. Since both the original and scaled signals are displayed in the same graph,
resize the plot legend to display the two labels and markers. The use of the dynamic
data type sets the signal labels automatically.
To run the VI continuously, place a While Loop. Position the While Loop
to enclose all the Express VIs and the graph. Now the VI is ready to be run.
Run the VI and observe the Waveform Graph. The output should appear as
shown in Figure 2-36. To extend the plot to the right-end of the plotting area, rightclick on the Waveform Graph and choose X Scale, then uncheck Loose Fit from
the shortcut menu. The graph shown in Figure 2-37 should appear.
If the plot runs too fast, a delay can be placed in the While Loop. To do this,
place a Time Delay Express VI (Functions Programming Timing Time
Delay) and set the delay time to 0.2 in the configuration window. This way, the loop
execution is delayed by 0.2 seconds in the BD shown in Figure 2-33.
Although this system runs successfully, no control of the signal frequency
and gain is available during its execution since all the parameters are set in the
configuration dialogs of the Express VIs. To gain such a flexibility, some
modifications need to be made.
To change the frequency at run time, place a Vertical Pointer Slide
control (Controls Modern Numeric Vertical Pointer Slide) on the FP and
wire it to the Frequency terminal of the Simulate Signal Express VI. The
control is labeled as Frequency. The Express VI can be resized to show more
terminals at the bottom of the expandable node. Resize the VI to show an additional
terminal below the Sine terminal. Then, click on this new terminal, error out by
default, to select Frequency from the list of the displayed terminals.
Next, replace the Scaling and Mapping Express VI with a Multiply
function (Functions Programming Numeric Multiply). Place another
Vertical Pointer Slide control and wire it to the y terminal of the Multiply
function to adjust the gain. This control is labeled as Gain. These modifications are
illustrated in Figure 2-38.
Now on the FP, set the maximum range of each slide control to 1000 for the
Frequency control and 5 for the Gain control, respectively. Also, set the default
values for these controls to 200 and 2, respectively.
By running this modified VI, it can be observed that the two signals get
displayed with the same label since the source of these signals, i.e. the Sine terminal
of the Simulate Signal Express VI, is the same. Also, due to the autoscale feature
of the Waveform Graph, the scaled signal appears unchanged while the Y axis of
the Waveform Graph changes appropriately. This is illustrated in Figure 2-39.
Let us now modify the property of the Waveform Graph. In order to disable
the autoscale feature, right-click on the Waveform Graph and uncheck Y Axis
AutoScale Y. The maximum and minimum scale can also be adjusted. In this
example -600 and 600 are used as the minimum and maximum values, respectively.
This is done by modifying the maximum and minimum scale values of the Y axis
with the Labeling tool. If the automatic tool selection mode is enabled, just click on
the maximum or minimum scale of the Y axis to enter any desired scale value. To
modify the labels displayed in the plot legend, right-click and choose Ignore
Attributes. Then, edit the labels to read Original and Scaled using the Labeling
tool. The changing of the properties of the Waveform Graph can also be
accomplished by using its properties dialog box. This box is brought up by rightclicking on the Waveform Graph and choosing Properties from the shortcut menu.
The completed FP is shown in Figure 2-40. With this version of the VI, the
frequency of the input signal and the gain of the output signal can be controlled
using the controls on the FP.
10
11
Build Array function is used for comparing the two signals, make sure that the
Concatenate Inputs option is unchecked from the shortcut menu. More details on
the use of the Build Array function can be found in [2].
A Waveform Graph (Controls Modern Graph Waveform Graph) is
then placed on the FP. Wire the output of the Build Array function to the input of
the Waveform Graph. Resize the plot legend to display the labels and edit them.
Similar to the example in the previous section, the AutoScale feature of the Y axis
should be disabled and the Loose Fit option should be unchecked along the X axis.
Place a Wait (ms) function (Functions Programming Timing Wait)
inside the While Loop to delay the execution in case the VI runs too fast. Rightclick on the milliseconds to wait terminal and choose Create Constant
from the shortcut menu to create and wire a Numeric Constant. Enter 200 in the
box created.
Figure 2-41 and Figure 2-42 illustrate the BD and FP of the designed signal
generation system, respectively. Save the VI as Lab02_ Regular_Waveform.vi and run
it. Change the signal type, gain and frequency values to see the original and scaled
signal in the Waveform Graph.
12
Figure 2-41: BD of signal generation and amplification system using regular VIs.
13
The waveform data type is not accepted by all the functions or subVIs. To
cope with this issue, the Y component (data value) of the waveform data type is
extracted to have the output signal as an array of data samples. This is done by
placing a Get Waveform Components function (Functions Programming
Waveform Get Waveform Components). Then, wire the signal out terminal
of the Basic Function Generator VI to the waveform terminal of the Get
Waveform Components function. Click on t0, the default terminal, of the Get
Waveform Components function and choose Y as the output to extract data values
from the waveform data type, see Figure 2-43. The remaining steps are the same as
those done for the version shown in Figure 2-41. In this version, however, the
processed signal is an array of double precision samples.
14
L2.3 Profile VI
The Profile tool is used to gather timing and memory usage information. Make sure
the VI is stopped before setting up a Profile window. Select Tools Profile
Performance and Memory to bring up a Profile window.
Place a checkmark in the Timing Statistics checkbox to display timing
statistics of the VI. The Timing Details option provides more detailed statistics of the
VI such as drawing time. To profile memory usage as well as timing, check the
Memory Usage checkbox after checking the Profile Memory Usage checkbox. Note
that this option can slow down the execution of the VI. Start profiling by clicking the
Start button on the profiler, then run the VI. A snapshot of the profiler information
can be obtained by clicking on the Snapshot button. After viewing the timing
information, click the Stop button. The profile statistics can be stored into a text file
by clicking the Save button.
An outcome of the profiler is exhibited in Figure 2-44 after running the
Lab02_Regular VI. More details on the use of the Profile tool can be found in [3].
15
L2.4 Bibliography
[1]
National Instruments, Getting Started with LabVIEW, Part Number 323427A01, 2003.
[2]
[3]
16
the number of samples being 256. Set the frequency ranges from 100 Hz to 400
Hz and set the amplitude ranges from 20 to 200. Generate a third signal with the
frequency f3 = (mod (lcm (f1, f2), 400) + 100) Hz, where mod and lcm denote the
modulus and least common multiple operation, respectively, and the amplitude
A3 being the sum of the amplitudes A1 and A2. Use the same sampling frequency
and number of samples as used for the first two signals. Display all the signals
using the legend on the same waveform graph and label them accordingly. When
not using the MathScript feature, it is easier to use the Express VIs.
3. Build a VI to generate two sinusoid signals the same as the ones in Experiment 2.
Generate a third signal with the frequency f3 = (gcd (f1, f2) + mean (f1, f2)) Hz,
where gcd and mean denote the greatest common divisor and the average
operation, respectively, and the amplitude A3 being the sum of the amplitudes A1
and A2. Use the same sampling frequency and number of samples as used for the
first two signals. Display all the signals using the legend on the same waveform
graph and label them accordingly. When not using the MathScript feature, it is
easier to use the Express VIs.
4. Build a VI to generate the first n prime numbers and store them using an
indexing array. Display the outcome.
17