Exercise 9
Exercise 9
This exercise provides additional experience with the Waveform palette, along with more
cluster and array operations. A VI will be setup to produce a modulated sine wave
followed by Fourier analysis.
Open a blank VI and go to the Block Diagram. Rightclick and select Waveform: Analog
Wfm: Generation: Sine Wfm. Alternatively, locate it with Quick Drop. Place two of these
icons on the Block Diagram. One will generate the fundamental or carrier wave at
frequency f0 and the second will be the modulation signal at frequency f1. Note that by
definition f0 > f1. Create a Front Panel numerical control on the frequency terminal of
the first sinewave generator and call it “Fundamental frequency (f0)”. Do the same on
the second and label it “Modulation frequency (f1)”. Create a control on one generator for
the terminal sampling info; this will produce a brown cluster icon on the Block
Diagram. Wire this to the second Sine Wfm VI so that both are setup the same way. This
control cluster sets the waveform sampling rate (Fs) and number of points (#s) in the
signal. The defaults are 1 kHz and 1000 points, respectively.
Next multiply the signal out terminals together using the multiplication function on the
Numeric Palette. Create an indicator on the Multiply output terminal; it will be a
waveform cluster. Doubleclick on the icon to locate the indicator on the Front Panel.
Rightclick on the edge of the cluster and Replace: Graph: Waveform Graph. It is
important to select the entire cluster and not one of its components (eg. t0, dt, or Y). This
graph will be the modulated output waveform.
In addition to the output waveform, both input signals should be monitored. Select
Waveform: Get Waveform Components and place on the Block Diagram. Wire the “signal
out” from the Sine Wave generator at f0 to the input. Click and drag the components icon
down to show two output terminals (Y and attributes). Alternatively, rightclick and
“Add Element”. Rightclick on the lower terminal, Select Item: dt. This corresponds to
the time separation between points. Wire a second “Get Wfm Components” VI to the
signal out terminal of the second Sine Wave generator that produces frequency f1. Only
the Y data is needed here.
The two waveforms will be plotted on the same Waveform Graph. In this exercise, the
needed information is bundled into a cluster. This cluster contains the starting xvalue,
dt, and a 2D array with data from both waveforms. Select Cluster, Class, & Variant:
Bundle and place it on the Block Diagram. Rightclick on the top input terminal and
create a floating point (DBL) constant of 0. Wire the second input terminal to the dt
value from the first waveform. The lower terminal will connect to a 2D array with both
sets of ydata. Select Array: Build Array and resize it to have two inputs. Connect the 1
D arrays (indicated by Y) to the two inputs of Build Array and wire the 2D output
(double orange wire) to the bottom terminal of the Bundle function. Consult the example
Block Diagram below.
Create an indicator at the output of the Bundle operation; doubleclick on the icon to
locate it on the Front Panel. Rightclick on the edge of the cluster and Replace: Graph:
Waveform Graph. As before, be careful to click on the cluster boundary and not the
internal components. You should now have a working VI. Select a modulation frequency
smaller than the fundamental frequency (f1 < f0) and verify operation. An example
Front Panel is shown below.
The waveforms on the graphs can be easily customized. Drag down the Plot Legend on
the multiplot graph to reveal the second channel and rightclick.
Fourier Analysis
The Fourier power spectrum of the modulated signal is given by the squared amplitude of
its Fourier transform |F(ν)|2. Select Waveform: Analog Wfm: Measurements: FFT Power
Spectrum and PSD.vi and place it on the Block Diagram. Connect a wire from the
modulated waveform to the time signal input terminal. Create an indicator on the
Power Spectrum/PSD output terminal. Doubleclick on the icon to find it on the Front
Panel and replace the cluster with a Waveform Graph.
Run the VI and examine the FFT graph. Rightclick on the Plot Legend icon and select
the line and symbol plot. You should see two peaks at frequencies f = f0 ± f1. The
sampling frequency Fs will set the time step dt of the temporal waveform, which defines
the maximum frequency in the Fourier spectrum. Choice of these parameters may make
it very difficult to resolve peaks in the power spectrum graph. One option is to zoomin
on the graph. Rightclick on the graph and select Visible Items: Graph Palette. Select
the middle tool in the top row to resize the xaxis display. The entire display can be
restored by clicking on the first tool in the second row.
Another option is to edit the displayed data range. Rightclick on the graph, select
Properties: Scales. Disable Autoscale and set an appropriate Maximum for the xaxis.
This operation can also be performed directly on the rightmost scale marker on the x
axis. Simply select it and change its value. An FFT power spectrum for f0 = 10 Hz, f1 =
2 Hz, and fmax = 20 Hz is shown below.
The maximum value of the xscale can also be set programatically inside the VI. For
example, the upperlimit of the frequency axis can be set to twice the value of f0 or f1,
depending on which one is larger. Go to the Block Diagram and select Comparison: Max
and Min. Wire the f0 and f1 controls to the two inputs labeled x and y. Multiply the
max(x,y) output by 2. Rightclick on the Power Spectrum graph icon and create a
Property Node: X Scale: Range: Maximum. Rightclick on the icon and select “Change to
Write”. Wire a connection from its input terminal to the output of the multiplication
operation.
When the VI is run, you will notice that the Property Node fails to limit the maximum
value of the frequency axis. This is caused by dataflow execution in the Block Diagram.
The code executes as soon as data becomes available; rearranging the icons will not
change the timing. The maximum value on the xaxis is set by the Property Node, but
that is overwritten by the FFT VI.
One solution is to force the order of execution with a Flat Sequence structure. Locate this
on the Structures palette and place it in the Block Diagram. Drop the Power Spectrum
icon inside the structure, rightclick on its boundary, and “Add Frame After”. Place the
Property Node in the second frame. This rigidly defines the order of execution. The
complete Block Diagram will look similar to this:
The Flat Sequence first draws the FFT graph, which is immediately followed by an xaxis
rescaling.
For the present situation, only a wire between the Power Spectrum VI error output and
the Property Node error input is necessary to establish the desired sequence.
To increase the capability of the example VI, the frequencies of the two spectral peaks
should be automatically identified. Go to the Block Diagram, rightclick and select
Cluster, Class, & Variant: Unbundle by Name. Wire the power spectrum bundle to its
input terminal. Rightclick on the icon and “Add Element”. Rightclick on the top output
terminal and Select Item: magnitude. Select df for the bottom terminal. Note that a 2D
array of x and yvalues is not available, which is why a Waveform Graph is used instead
of an XY Graph. The terminal labeled “magnitude” holds a 1D array of yvalues ( yi).
Select Array: Max & Min and place it on the Block Diagram near the Unbundle operation.
Wire the 1D array from magnitude to the input of Min & Max. We are interested in the
index of the largest yvalue. The frequency corresponding to this peak is found by
multiplying its index (an integer) times df. Display the result as an indicator and confirm
it matches one of the peaks on the graph.
There is a second peak in the FFT spectrum that will have the same or slightly lower
magnitude (this is due to sampling imprecision/noise). There are many possibilities for
determining its frequency. A simple method is to replace the magnitude of the detected
first peak with zero and repeating the maximum search. This is accomplished with the
function Array: Replace Array Subset wired as shown below.
LabView has a builtin utility that can accomplish multiple spectral peak detection.
Rightclick on the Block Diagram and select Waveform: Analog Wfm: Measurements:
Extract Multiple Tone Information VI. Wire the modulated time signal waveform to its
input. Rightclick on the multiple tone information output terminal and create an
indicator on Front Panel. Run the VI and check that two frequencies are detected by
scrolling through the two component cluster (select index 0 and 1 on the Front Panel).