In this section, let us apply the LabVIEW MathScript function conv to compute the convolution of two signals. One can choose various values of the time interval
Convolution Example 1
In this example, use the function conv to compute the convolution of the signals
Compare the approximation
conv with the theoretical value
Compute the mean squared error (MSE) between the true and approximated values using the following equation:
where
As you can see here, the main program is written as a .m file and placed inside LabVIEW as a LabVIEW MathScript node by invoking Functions → Programming →Structures → MathScript. The .m file can be typed in or copied and pasted into the LabVIEW MathScript node. The inputs to this program consist of an approximation pulse width
![]() |
After adding these inputs, create controls to allow one to alter the inputs interactively via the front panel. By right-clicking on the border, add the outputs in a similar manner. An important consideration is the selection of the output data type. Set the outputs to consist of MSE, actual or true convolution output y_ac and approximated convolution output y. The first output is a scalar quantity while the other two are one-dimensional vectors. The output data types should be specified by right-clicking on the outputs and selecting the Choose Data Type option (see Figure 2).
![]() |
Next write the following .m file textual code inside the LabVIEW MathScript node:
t=0:Delta:8;
Lt=length(t);
x1=exp(-a*t);
x2=exp(-b*t);
y=Delta*conv(x1,x2);
y_ac=1/(a-b)*(exp(-b*t)-exp(-a*t));
MSE=sum((y(1:Lt)-y_ac).^2)/Lt
With this code, a time vector t is generated by taking a time interval of Delta for 8 seconds. Convolve the two input signals, x1 and x2, using the function conv. Compute the actual output y_ac using Equation (1). Measure the length of the time vector and input vectors by using the command length(t). The convolution output vector y has a different size (if two input vectors m and n are convolved, the output vector size is m+n-1). Thus, to keep the size the same, use a portion of the output corresponding to y(1:Lt) during the error calculation.
Use a waveform graph to show the waveforms. With the function Build Waveform (Functions → Programming → Waveforms → Build Waveforms), one can show the waveforms across time. Connect the time interval Delta to the input dt of this function to display the waveforms along the time axis (in seconds).
Merge together and display the true and approximated outputs in the same graph using the function Merge Signal (Functions → Express → Signal Manipulation → Merge Signals). Configure the properties of the waveform graph as shown in Figure 3.
![]() |
Figure 4 illustrates the completed block diagram of the numerical convolution.
![]() |
Figure 5 shows the corresponding front panel, which can be used to change parameters. Adjust the input exponent powers and approximation pulse-width Delta to see the effect on the MSE.
![]() |
Convolution Example 2
Next, consider the convolution of the two signals
rect a rectangular function defined as
Let
![]() |
Figure 7 illustrates the corresponding front panel where
Decorations.
![]() |
Convolution Example 3
In this third example, compute the convolution of the signals shown in Figure 8.
![]() |
Figure 9 shows the block diagram for this third convolution example and Figure 10 the corresponding front panel. The signals
![]() |
![]() |






















