0% found this document useful (0 votes)
19 views6 pages

Exercise 9

This document provides instructions for an exercise using LabView to generate a modulated sine wave, analyze its Fourier spectrum, and identify the spectral peaks. The exercise involves generating two sine waves at different frequencies, multiplying them together, analyzing the Fourier spectrum using an FFT, and programmatically identifying the two spectral peaks in the modulated signal.

Uploaded by

Mr Grach
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

Exercise 9

This document provides instructions for an exercise using LabView to generate a modulated sine wave, analyze its Fourier spectrum, and identify the spectral peaks. The exercise involves generating two sine waves at different frequencies, multiplying them together, analyzing the Fourier spectrum using an FFT, and programmatically identifying the two spectral peaks in the modulated signal.

Uploaded by

Mr Grach
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PHYC 500: Introduction to LabView

M.P. Hasselbeck, University of New Mexico

Exercise 9 (v 1.1) Spectral content of waveforms

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. Right­click 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 sine­wave 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. Double­click on the icon to locate the indicator on the Front Panel.
Right­click 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, right­click and
“Add Element”. Right­click 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 x­value,
dt, and a 2­D array with data from both waveforms. Select Cluster, Class, & Variant:
Bundle and place it on the Block Diagram. Right­click 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 2­D array with both
sets of y­data. Select Array: Build Array and re­size it to have two inputs. Connect the 1­
D arrays (indicated by Y) to the two inputs of Build Array and wire the 2­D 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; double­click on the icon to
locate it on the Front Panel. Right­click 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 multi­plot graph to reveal the second channel and right­click.
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. Double­click 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. Right­click 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 zoom­in
on the graph. Right­click on the graph and select Visible Items: Graph Palette. Select
the middle tool in the top row to re­size the x­axis 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. Right­click on the graph, select
Properties: Scales. Disable Autoscale and set an appropriate Maximum for the x­axis.
This operation can also be performed directly on the right­most 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 x­scale can also be set programatically inside the VI. For
example, the upper­limit 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. Right­click on the Power Spectrum graph icon and create a
Property Node: X Scale: Range: Maximum. Right­click 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; re­arranging the icons will not
change the timing. The maximum value on the x­axis 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, right­click 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 x­axis
rescaling.

A simpler and more efficient approach to dataflow programming can sometimes be


implemented with error handling terminals. Error information can be forced to
propagate through a sequence of component VIs by wiring the error cluster serially in the
Block Diagram. This is illustrated with modifications to the above VI as shown below:
The error cluster is identified by the thick yellow­white wire. The path of the wire forces
the f1 sine wave generator to execute first, followed by the f0 generator, the FFT
operation, and finally the Property Node write. A Simple Error Handler VI (found in the
Dialog & User Interface palette) can be optionally added to alert the user to any problems
encountered in these four operations.

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.

Locate spectral peaks

To increase the capability of the example VI, the frequencies of the two spectral peaks
should be automatically identified. Go to the Block Diagram, right­click and select
Cluster, Class, & Variant: Unbundle by Name. Wire the power spectrum bundle to its
input terminal. Right­click on the icon and “Add Element”. Right­click on the top output
terminal and Select Item: magnitude. Select df for the bottom terminal. Note that a 2­D
array of x­ and y­values is not available, which is why a Waveform Graph is used instead
of an XY Graph. The terminal labeled “magnitude” holds a 1­D array of y­values ( yi).

Select Array: Max & Min and place it on the Block Diagram near the Unbundle operation.
Wire the 1­D array from magnitude to the input of Min & Max. We are interested in the
index of the largest y­value. 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 built­in utility that can accomplish multiple spectral peak detection.
Right­click on the Block Diagram and select Waveform: Analog Wfm: Measurements:
Extract Multiple Tone Information VI. Wire the modulated time signal waveform to its
input. Right­click 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).

You might also like