Introduction To LabVIEW
Introduction To LabVIEW
Introduction to LabVIEW
The objective of this lab is to offer an initial hands-on experience in building a VI. One can
launch LabVIEW by double-clicking on the LabVIEW icon, which opens the dialog window
shown in Fig. 1.
Building a Simple VI
To become familiar with the LabVIEW programming environment, let us calculate the sum
and average of two input values in the following step-by-step example.
To create a new VI, click on the Blank VI under New, as shown in Fig. 2. This can also be
done by choosing File → New VI from the menu. As a result, a blank front panel and a blank
block diagram window appear, see Fig. 2. Remember that a front panel and block diagram
coexist when one builds a VI, meaning that every VI will have both a front panel and an
associated block diagram.
Fig. 2: Blank VI
The number of VI inputs and outputs is dependent on the VI function. In this example, two
inputs and two outputs are needed, one output generating the sum and the other
generating the average of the two input values. Create the inputs by locating two numeric
controls on the front panel. This can be done by right-clicking on an open area of the front
panel to bring up the Controls palette, followed by choosing Controls → Modern → Numeric
→ Numeric Control. Each numeric control automatically places a corresponding terminal
icon on the block diagram. Double-clicking on a numeric control highlights its counterpart
on the block diagram and vice versa.
Next, label the two inputs as x and y using the Labeling tool from the Tools Palette, which
can be displayed by choosing View → Tools Palette from the menu bar. Choose the Labeling
tool and click on the default labels, Numeric and Numeric 2, to edit them. Alternatively, if
the automatic tool selection mode is enabled by clicking Automatic Tool Selection in the
Tools Palette, the labels can be edited by simply double-clicking on the default labels.
Editing a label on the front panel changes its corresponding terminal icon label on the block
diagram and vice versa.
Similarly, the outputs are created by locating two numeric indicators (Controls → Modern →
Numeric →Numeric Indicator) on the front panel. Each numeric indicator automatically
places a corresponding terminal icon on the block diagram. Edit the labels of the indicators
to read “Sum“ and “Average.”
For a better visual appearance, one can align, distribute and resize objects on a front panel
window using the front panel toolbar. To do this, select the objects to be aligned or
distributed and apply the appropriate option from the toolbar menu. Fig.3 shows the
configuration of the front panel just created.
Now build a graphical code on the block diagram to perform the summation and averaging
operations. Note that <Ctrl-E> toggles between a front panel and a block diagram window. If
objects on a block diagram are too close to insert other functions or VIs in-between, one can
insert a horizontal or vertical space by holding down the <Ctrl> key to create space
horizontally and/or vertically. As an example, Fig.4b illustrates a horizontal space inserted
between the objects shown in Fig.4a.
Fig. 4: Inserting Horizontal/Vertical Space: (a) Creating Space While Holding Down
the <Ctrl> Key, (b) Inserted Horizontal Space.
Next, place an Add function (Functions →Express →Arithmetic & Comparison →Express
Numeric →Add) and a Divide function (Functions →Express →Arithmetic & Comparison
→Express Numeric →Divide) on the block diagram. Enter the divisor, in this case 2, in a
Numeric Constant(Functions →Express →Arithmetic & Comparison →Express Numeric
→Numeric Constant) and connect it to the y terminal of the Divide function using the Wiring
tool.
To achieve proper data flow, wire functions, structures and terminal icons on a block
diagram using the Wiring tool. To wire these objects, point the Wiring tool at the terminal of
the function or subVI to be wired, left-click on the terminal, drag the mouse to a destination
terminal and left-click once again. Fig.5 illustrates the wires placed between the terminals of
the numeric controls and the input terminals of the Add function. Notice that the label of a
terminal gets displayed whenever one moves the cursor over the terminal if the automatic
tool selection mode is enabled. Also, note that the Run button on the toolbar remains
broken until one completes the wiring process.
Fig. 5: Wiring Block Diagram Objects.
For better block diagram readability, one can clean up wires hidden behind objects or
crossed over other wires by right-clicking on them and choosing Clean Up Wire from the
shortcut menu. Any broken wires can be cleared by pressing <Ctrl-B> or Edit →Remove
Broken Wires.
To view or hide the label of a block diagram object, such as a function, right-click on the
object and check (or uncheck) Visible Items →Label from the shortcut menu. Also, one can
show a terminal icon corresponding to a numeric control or indicator as a data type terminal
icon by right-clicking on the terminal icon and unchecking View As Icon from the shortcut
menu. Fig.6 shows an example where the numeric controls and indicators are depicted as
data type terminal icons. The notation DBL indicates double precision data type.
It is worth noting that there is a shortcut to build the above VI. Instead of choosing the
numeric controls, indicators or constants from the Controls or Functions palette, one can
use the shortcut menu Create, activated by right-clicking on a terminal of a block diagram
object such as a function or a subVI. As an example of this approach, create a blank VI and
locate an Add function. Right-click on its x terminal and choose Create →Control from the
shortcut menu to create and wire a numeric control or input. This locates a numeric control
on the front panel as well as a corresponding terminal icon on the block diagram. The label
is automatically set to x. Create a second numeric control by right-clicking on the y terminal
of the Add function. Next, right-click on the output terminal of the Add function and choose
Create →Indicator from the shortcut menu. A data type terminal icon, labeled as x+y, is
created on the block diagram as well as a corresponding numeric indicator on the front
panel.
Next, right-click on the y terminal of the Divide function to choose Create →Constant from
the shortcut menu. This creates a numeric constant as the divisor and wires its y terminal.
Type the value 2 in the numeric constant. Right-click on the output terminal of the Divide
function, labeled as x/y, and choose Create →Indicator from the shortcut menu. If the
wrong option is chosen, the terminal does not get wired. An incorrect terminal option can
easily be changed by right-clicking on the terminal and choosing Change to Control from the
shortcut menu.
To save the created VI for later use, choose File →Save from the menu or press <Ctrl-S> to
bring up a dialog window to enter a name. Type “Sum and Average” as the VI name and click
Save.
To test the functionality of the VI, enter some sample values in the numeric controls on the
front panel and run the VI by choosing Operate →Run, by pressing <Ctrl-R> or by clicking the
Run button on the toolbar. From the displayed output values in the numeric indicators, the
functionality of the VI can be verified. Fig.7 illustrates the outcome after running the VI with
two inputs, 10 and 15.
Fig. 7: VI Verification
SubVI Creation
If it is desired to use a VI as part of a higher-level VI, one needs to configure its connector
pane. A connector pane assigns inputs and outputs of a subVI to its terminals through which
data are exchanged. A connector pane can be displayed by right-clicking on the top right
corner icon of a front panel and selecting Show Connector from the shortcut menu.
The default pattern of a connector pane is determined based on the number of controls and
indicators. In general, the terminals on the left side of a connector pane pattern are used for
inputs and the ones on the right side for outputs. One can add terminals to or remove them
from a connector pane by right-clicking and choosing Add Terminal or Remove Terminal
from the shortcut menu. If the number of inputs/outputs or the distribution of terminals are
changed, the connector pane pattern can be replaced with a new one by right-clicking and
choosing Patterns from the shortcut menu. Once a pattern is selected, one needs to
reassign each terminal to a control or an indicator by using the Wiring tool or by enabling
the automatic tool selection mode.
Fig.8a illustrates how to assign a Sum and Average VI terminal to a numeric control. The
completed connector pane is shown in Fig.8b. Notice that the output terminals have thicker
borders. The color of a terminal reflects its data type.
Considering that a subVI icon is displayed on the block diagram of a higher-level VI, it is
important to edit the subVI icon for it to be explicitly identifiable. Double-clicking on the
top-right corner icon of a block diagram opens the Icon Editor. The Icon Editor tools are
similar to those in other graphical editors, such as Microsoft Paint. Editing the Sum and
Average VI icon is illustrated in Fig.9.
A subVI can also be created from a section of a VI. To do so, select the nodes on the block
diagram to be included in the subVI, as shown in Fig.10a. Then, choose Edit →Create SubVI
to insert a new subVI icon. Fig.10b illustrates the block diagram with an inserted subVI. One
can open and edit this subVI by double-clicking on its icon on the block diagram. Save this
subVI as Sum and Average.vi. This subVI performs the same function as the original Sum and
Average VI.
Fig. 10: Creating a SubVI: (a) Selecting Nodes to Make a SubVI, (b) Inserted SubVI Icon.
Now let us consider another example to understand the use of structures and subVIs. In this
example, we use a VI to show the sum and average of two input values, which are altered in
a continuous fashion. If the average of the two inputs becomes greater than a preset
threshold value, a LED warning light turns on.
First, build a front panel as shown in Fig.11a. For the inputs, consider two Knobs (Controls
→Modern →Numeric →Knob). Adjust the size of the knobs by using the Positioning tool.
One can modify knob properties such as precision and data type by right-clicking and
choosing Properties from the shortcut menu. A Knob Properties dialog box opens and an
Appearance tab is shown by default. Edit the label of one of the knobs to read Input 1.
Select the Data Range tab, click Representation and select Byte to change the data type
from double precision to byte. One can also perform this by right-clicking on the knob and
choosing Representation →Byte from the shortcut menu. In the Data Range tab, a default
value needs to be specified. In this example, the default value is considered to be 0. The
default value can be set by right-clicking on the control and choosing Data Operations
→Make Current Value Default from the shortcut menu. Also, this control can be set to a
default value by right-clicking and choosing Data Operations →Reinitialize to Default Value
from the shortcut menu.
Label the second knob as Input 2 and repeat all the adjustments as carried out for the first
knob except for the data representation part. Specify the data type of the second knob to be
double precision to demonstrate the difference in the outcome. As the final front panel
configuration step, align and distribute the objects using the appropriate buttons on the
front panel toolbar.
To set the outputs, locate and place a numeric indicator, a round LED (Controls →Modern
→Boolean →Round LED) and a gauge (Controls →Modern →Numeric →Gauge). Edit the
labels of the indicators as shown in Fig.11.
Fig. 11: Example of Structure and SubVI: (a) Front Panel, (b) Block Diagram.
To run the VI continuously, use a while loop structure. Choose Functions →Programming
→Structures →While Loopto create a while loop. Change the size by dragging the mouse to
enclose the objects in the while loop, as illustrated in Fig.12.
Once this structure is created, its boundary, together with the loop iteration terminal and
conditional terminal , get shown on the block diagram. If one creates the while loop by
using Functions →Programming →Structures → While Loop, the Stop button is not included
as part of the structure. One can create this button by right-clicking on the conditional
terminal and choosing Create →Control from the shortcut menu. It is possible to wire a
Boolean condition to a conditional terminal, instead of a Stop button, to stop the loop
programmatically.
Next run the VI to verify its functionality. After clicking the Run button on the toolbar, adjust
the knobs to alter the inputs. Verify whether the average and sum are displayed correctly in
the gauge and numeric indicators. Note that only integer values can be entered via the Input
1 knob while real values can be entered via the Input 2 knob. This is due to the data types
associated with these knobs. The Input 1 knob is set to byte type, in other words, I8 or 8-bit
signed integer. As a result, one can enter only integer values within the range -128 and 127.
Considering that the minimum and maximum values of this knob are set to 0 and 10,
respectively, one can enter only integer values from 0 to 10 for this input.
Use the Probe tool to observe data that are being passed while a VI is running. A probe can
be placed on a wire by using the Probe tool or by right-clicking on a wire and choosing Probe
from the shortcut menu. Probes can also be placed while a VI is running.
Placing probes on wires creates probe windows through which one can observe
intermediate values. As an example of using custom probes, use four probe windows at the
probe locations 1 through 4 in the Sum and Average VI to probe the values at those
locations. These probes and their locations are illustrated inFig.14.
Fig. 14: Probe Tool.
Profile Tool
With the Profile tool, one can gather timing and memory usage information. Make sure to
stop the VI before selecting Tools →Profile →Performance and Memory to open a Profile
window.
Place a checkmark in the Timing Statistics checkbox to display timing statistics of the VI. The
Timing Details option offers more detailed VI statistics 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 VI execution. Start
profiling by clicking the Start button on the profiler, then run the VI. Obtain a snapshot of
the profiler information by clicking on the Snapshot button. After viewing the timing
information, click the Stop button. The profile statistics can be stored in a text file by clicking
the Save button.
An outcome of the profiler is shown in Fig.15 after running the Sum and Average or L1.1 VI.
Fig. 15: Profile Window after Running Sum and Average VI.
Arithmetic Operations
+ addition
- subtraction
* multiplication
As an example, to evaluate the expression a3 + bd − 4c , where a = 1.2, b = 2.3, c = 4.5 and d
= 4, type the following commands in the Command Window of MATLAB to get the answer:
>> a=1.2;
>> b=2.3;
>> c=4.5;
>> d=4;
>> a^3+sqrt(b*d)-4*c
ans =
-13.2388
Note the semicolon after each variable assignment. If the semicolon is omitted, the
interpreter echoes back the variable value.
Vector Operations
Consider the vectors x =[x1,x2,...,xn] and y =[y1,y2,...,yn] . The following operations indicate
the resulting vectors:
x*.y =[ x1y1,x2y2,...,xnyn]
x.^p =[x1p,x2p,...,xnp]
Note that because the boldfacing of vectors/matrices are not used in .m files, in the
notation adopted in this book, no boldfacing of vectors/matrices is shown to retain
consistency with .m files.
The arithmetic operators + and – can be used to add or subtract matrices, vectors or scalars.
Vectors denote one-dimensional arrays and matrices denote multidimensional arrays. For
example,
>> x=[1,3,4]
>> y=[4,5,6]
>> x+y
ans=
5 8 10
In this example, the operator + adds the elements of the vectors x and y, element by
element, assuming that the two vectors have the same dimension, in this case 1×3 or one
row with three columns. An error occurs if one attempts to add vectors having different
dimensions. The same applies for matrices.
To compute the dot product of two vectors (in other words, ∑xiyi ), use the multiplication
operator ‘*’ as follows:
>> x*y'
ans =
43
Note the single quote after y denotes the transpose of a vector or a matrix.
To compute an element-by-element multiplication of two vectors (or two arrays), use the
following operator:
>> x .* y
ans =
4 15 24
Complex Numbers
LabVIEW MathScript supports complex numbers. The imaginary number is denoted with the
symbol i or j, assuming that these symbols have not been used any other place in the
program. It is critical to avoid such a symbol conflict for obtaining correct outcome. Enter
the following and observe the outcomes:
>> z=3 + 4i % note the multiplication sign ‘*’ is not needed after 4
One can also define an imaginary number with any other user-specified variables. For
example, try the following:
>> img=sqrt(-1)
>> z=3+4*img
>> exp(pi*img)
Array Indexing
In .m files, all arrays (vectors) are indexed starting from 1 − in other words, x(1) denotes the
first element of the array x. Note that the arrays are indexed using parentheses (.) and not
square brackets [.], as done in C/C++. To create an array featuring the integers 1 through 6
as elements, enter:
>> x=[1,2,3,4,5,6]
>> x=1:6
>> x=1:2:6
ans =
135
>> ii=2:4:17
>> jj=20:-2:0
>> ii=2:(1/10):4
One can easily extract numbers in a vector. To concatenate an array, the example below
shows how to use the operator ‘[ ]’:
>> x(3:7)
>> x(2:2:length(x))
Allocating Memory
One can allocate memory for one-dimensional arrays (vectors) using the command zeros.
The following command allocates memory for a 100-dimensional array:
>> y=zeros(100,1);
>> y(30)
ans =
0
One can allocate memory for two-dimensional arrays (matrices) in a similar fashion. The
command
>> y=zeros(4,5)
defines a 4 by 5 matrix. Similar to the command zeros, the command ones can be used to
define a vector containing all ones,
>> y=ones(1,5)
ans=
11111
Some common special characters used in .m files are listed below for later reference:
Symbol Meaning
pi π(3.14.....)
Inf Represents +∞
indicates the end of a row in a matrix; also used to suppress printing on the screen
;
(echo off)
denotes transpose of a vector or a matrix; also used to define strings, for example,
‘
str1='DSP'
denotes continuation; three or more periods at the end of a line continue current
…
function to next line
Function Meaning
>> x=1:10;
>> length(x)
ans =
10
The function find returns the indices of a vector that are non-zero. For example,
I = find(x>4) finds all the indices of x greater than 4. Thus, for the above example:
>> find(x> 4)
ans =
5 6 7 8 9 10
Control Flow
• if statements
• switch statements
• for loops
• while loops
• break statements
The constructs if, for, switch and while need to terminate with an end statement. Examples
are provided below:
if
>> x=-3;
if x>0
str='positive'
elseif x<0
str='negative'
elseif x== 0
str='zero'
else
str='error'
end
while
>> x=-10;
while x<0
x=x+1;
end
for loop
>> x=0;
for j=1:10
x=x+j;
end
The above code computes the sum of all the numbers from 1 to 10.
break
With the break statement, one can exit early from a for or a while loop:
>> x=-10;
while x<0
x=x+2;
if x = = -2
break;
end
end
LabVIEW MathScript supports the relational and logical operators listed below.
Relational Operators
Symbol Meaning
== equal
~= not equal
Logical Operators
Symbol Meaning
& AND
∣ OR
~ NOT
For instance, to write a program to compute the average (mean) of a vector x, the program
should use as its input the vector x and return the average value. To write this program,
follow the steps outlined below.
x=1:10
L=length(x);
sum=0;
for j=1:L
sum=sum+x(j);
end
From the Editor pull-down menu, go to File → Save Script As and enter average.m for the
file name. Then click on the Run script button to run the program. Fig.16 shows the LabVIEW
MathScript interactive window after running the program.
Fig. 16: LabVIEW MathScript Interactive Window after Running
the Program Average
Sound Generation
Assuming the computer used has a sound card, one can use the function sound to play back
speech or audio files through its speakers. That is, sound(y,FS) sends the signal in a vector y
(with sample frequency FS) out to the speaker. Stereo sounds are played on platforms that
support them, with y being an N-by-2 matrix.
>> t=0:1/8000:1;
>> x=cos(2*pi*400*t);
>> sound(x,8000);
>> sound(noise,8000);
The function randn generates Gaussian noise with zero mean and unit variance.
Signal Display
Several tools are available in LabVIEW to display data in a graphical format. Throughout the
book, signals in both the time and frequency domains are displayed using the following two
graph tools.
Often a waveform graph is tied with the function Build Waveform(Function→ Programming
→ Waveform → Build Waveform) to calibrate the x scale (which is time scale for signals), as
shown in Fig.18.
Create an XY graph from a front panel by choosing Controls→ Express → XY Graph. Fig.19
shows an XY graph and its different elements.
Fig. 19: XY Graph
An XY graph displays a signal at a non-constant rate, and one can tie together its X and Y
vectors to display the signal via the Build XY Graph function. This function automatically
appears on the block diagram when placing an XY graph on the front panel, as shown in Fig.
20. Note that one can use the function Bundle (Functions → Programming → Cluster &
Variant → Bundle) instead of Build XY Graph.
Hybrid Programming
As stated earlier, the LabVIEW MathScript feature can be used to perform hybrid
programming, in other words, a combination of textual .m files and graphical objects.
Normally, it is easier to carry out math operations via .m files while maintaining user
interfacing, interactivity and analysis in the more intuitive graphical environment of
LabVIEW. Textual .m file codes can be typed in or copied and pasted into LabVIEW
MathScript nodes.
Now build the same program average using a LabVIEW MathScript node. The inputs to this
program consist of x and y. To add these inputs, right-click on the border of the LabVIEW
MathScript node and click on the Add Input option (see Fig.22).
After adding these inputs, create controls to change the inputs interactively via the front
panel. By right-clicking on the border, add outputs in a similar manner. An important issue
to consider is the selection of output data type. The outputs of the Sum and Average VI are
scalar quantities. Choose data types by right-clicking on an output and selecting the Choose
Data Type option (see Fig. 23).
Fig. 23: (a) Adding Outputs, (b) Choosing Data Types
Finally, add numeric indicators in a similar fashion as indicated earlier. Fig. 24 shows the
completed block diagram and front panel.
Fig. 24: (a) Completed Block Diagram, (b) Completed Front Panel
In this section, let us see how to generate and display a periodic continuous-time signals or
pulses in the time domain. One can represent such signals with a function of time. For
simulation purposes, a representation of time tis needed. Note that the time scale is
continuous while computer programs operate in a discrete fashion. This simulation can be
achieved by considering a very small time interval. For example, if a 1-second duration
signal in millisecond increments (time interval of 0.001 second) is considered, then one
sample every 1 millisecond and a total of 1000 samples are generated for the entire signal.
This continuous-time signal approximation is discussed further in later chapters. It is
important to note that there is a finite number of samples for a continuous-time signal, and,
to differentiate this signal from a discrete-time signal, one must assign a much higher
number of samples per second (very small time interval).
Fig. 25 shows two continuous-time signals x1(t) and x2(t) with a duration of 3 seconds. By
setting the time interval dt to 0.001 second, there is a total of 3000 samples at
t=0,0.001,0.002,0.003,.......,2.999 seconds.
0 2≤t<3
To simulate this signal, use the LabVIEW MathScript functions ones and zeros. The signal
value is zero during the first second, which means the first 1000 samples are zero. This
portion of the signal is simulated with the function zeros(1,1000). In the next second (next
1000 samples), the signal value is 2, and this portion is simulated by the function
2*ones(1,1000). Finally, the third portion of the signal is simulated by the function
zeros(1,1000). In other words, the entire duration of the signal is simulated by the following
.m file function:
2t 0≤t<1
0 2≤t<3
Use a linearly increasing or decreasing vector to represent the linear portions. The time
vectors for the three portions or segments of the signal are 0:dt:1-dt, 1:dt:2-dt and 2:dt:3-
dt. The first segment is a linear function corresponding to a time vector with a slope of 2;
the second segment is a linear function corresponding to a time vector with a slope of -2
and an offset of 4; and the third segment is simply a constant vector of zeros. In other
words, simulate the entire duration of the signal for any value of dt by the following .m file
function:
Fig. 26 and Fig. 27 show the block diagram and front panel of the above signal generation
system, respectively. Display the signals using a Waveform Graph(Controls→ Express →
Waveform Graph) and a Build Waveform function (Function→ Programming → Waveform
→ Build Waveform). Note that the default data type in MathScript is double precision scalar.
So whenever an output possesses any other data type, one needs to right-click on the
output and select the Choose Data Type option. In this example, x1 and x2 are double
precision one-dimensional arrays that are specified accordingly.
In this section, build a simple periodic signal generation system in hybrid mode to set the
stage for the chapters that follow. This system involves generating a periodic signal in
textual mode and displaying it in graphical mode. Modify the shape of the signal (sine,
square, triangle or sawtooth) as well as its frequency and amplitude by using appropriate
front panel controls. The block diagram and front panel of this system using a LabVIEW
MathScript node are shown in Fig. 28 and Fig. 29, respectively. The front panel includes the
following three controls:
Waveform type – Select the shape of the input waveform as either sine, square, triangular
or sawtooth waves.
Finally, display the waveforms with a Waveform Graph (Controls→ Express → Waveform
Graph) and a Build Waveform function (Function→ Programming → Waveform → Build
Waveform).
Note:
Sum and average VI, its sub VI, insert it into a physical system and showing some warning
based on threshold using control flow, probe tool, profile tool, programming of sum and
average Math script, signal display and signal generation.
In addition to the results you inferred in your own words you should do the following and
write it as a report. The following exercises will be evaluated and added to the grades.
Lab Exercises to be submitted before the next LAB class.
Exercise 1
where μ denotes the average of the array x. For x, use all the integers from 1 to 1000.
Exercise 2
Build a VI to check whether a given positive integer n is a prime number and display a
warning message if it is not a prime number.
Exercise 3
Build a VI to generate the first N prime numbers and store them using an indexing array.
Display the outcome.
Exercise 4
Exercise 5
Write a .m file code to add all the numbers corresponding to the even indices of an array.
For instance, if the array x is specified as x = [1, 3, 5, 10], then 13 (= 3+10) should be
returned. Use the program to find the sum of all even integers from 1 to 1000. Run your
code using the LabVIEW MathScript interactive window. Also, redo the code where x is the
input vector and y is the sum of all the numbers corresponding to the even indices of x.
Exercise 6
L=length(x);
for j=1:L
if x(j) < 0
x(j)=-x(j);
end
end
Rewrite this program without using a for loop.
Exercise 7
0.2 t≥0.2
x(t)={
−0.2 t<0.2
For t, use 1000 random numbers generated via the function rand.
Exercise 8
Build a hybrid VI to generate two sinusoid signals with the frequencies f 1 Hz and f2 Hz and
the amplitudes A1 and A2, based on a sampling frequency of 8000 Hz with the number of
samples being 256. Set the frequency ranges from 100 to 400 Hz and set the amplitude
ranges from 20 to 200. Generate a third signal with the frequency f 3 = (mod (lcm (f1, f2), 400)
+ 100) Hz, where mod and lcm denote the modulus and least common multiple operation,
respectively, and the amplitude A3 is the sum of the amplitudes A1 and A2. Use the same
sampling frequency and number of samples as specified for the first two signals. Display all
the signals using the legend on the same waveform graph and label them accordingly.
Exercise 9