By Adarsh Narasimhamurthy, MathWorks and Eric Wetjen, MathWorks

Function generators are commonly used for testing physical devices, hardware designs, or receiver algorithms. However, they may not always provide the test signal required. In this case, it is necessary to create a custom waveform. With a custom waveform you can incorporate real-world conditions into the device under test. For example, you can generate signals corrupted by noise, or precisely delayed signals.

While creating a custom waveform in MATLAB^{®} is straightforward, downloading it for use can be challenging. One option is to save the custom waveform onto a USB flash drive and transfer it to the instrument. While this procedure works, it cannot be automated. A more efficient approach uses a single MATLAB script to both create a custom waveform and download it to the instrument. However, such a MATLAB script involves writing Standard Command for Programmable Instruments (SCPI) code or using Interchangeable Virtual Instruments (IVI) drivers to connect to and set up the instrument and download the custom signal. Other challenges include the need to identify the right set of SCPI commands, the non-portability of SCPI commands across instruments, and the difficulty of importing and calling functions provided by the IVI driver.

The Quick-Control Function Generator in Instrument Control Toolbox™ greatly simplifies the task of downloading the custom waveform. It provides a simple interface that lets you download a custom waveform to an instrument without programming with an IVI driver or using SCPI commands.

This article demonstrates a simple workflow for creating and downloading custom waveforms to an arbitrary waveform generator (AWG) using MATLAB and Quick-Control Function Generator.

A quadratic chirp signal is used to characterize and test the response of a bandpass filter hardware prototype to a periodically waxing and waning frequency signal. Using a quadratic chirp avoids the need for manual frequency adjustment, and enables a smooth characterization of the frequency response of the hardware prototype.

Our sample application requires the following quadratic chirp signal:

\[f_i(t)=f_0 + \beta t^2\]

where \(\beta=(f_1-f_0)/t^2\), \(f_i\) is the instantaneous frequency at time *\(t\), \(f_0\)* is the frequency at time *\(t=0\)*, and \(f_1\) is the frequency at time \(t_1\) specified by the user.

To subject the hardware prototype to real-world conditions, we need to characterize its performance in the presence of additive noise. We create a custom waveform in MATLAB, and then use Quick-Control Function Generator to download and generate this waveform from an off-the-shelf AWG (Figure 1).

While you can use Quick-Control Function Generator with any AWG that has an IVI-C driver, you do not need to program with the IVI driver. This simplifies the process of writing code to remotely connect to and control the instrument.

The workflow consists of four steps:

- Create the signal in MATLAB.
- Establish communication with the AWG.
- Upload the waveform to the AWG.
- Start the waveform generation.

The `chirp`

function in Signal Processing Toolbox™ can generate samples of a frequency-swept cosine signal at the time instances defined in array \(t\). To use the `chirp`

function, we need to define the instantaneous frequency at time \(0\), \(f_0\), and the instantaneous frequency at time \(t_1\), \(f_1\). We also have the option of setting the sweep method. We select the quadratic method.

The following MATLAB script generates the `chirp`

signal.

The `spectrogram`

command lets us visualize the amplitude and frequency of the signal as a function of time (Figure 2). As the red coloring in the plot shows, the signal energy is most intense at 100 Hz and the frequency ramps down to 50 Hz after 1 second, as we would expect from our signal definition.

To simulate real-world conditions, we inject additive white Gaussian noise into the chirp signal. To do this, we call the `randn`

function, which returns standard normal distributed pseudorandom numbers. We use the following MATLAB code to generate and plot the spectrogram of the noisy signal.

The spectrogram plot of the noise-injected quadratic signal shows that the addition of white noise makes the signal energy non-zero at frequencies outside the chirp frequency (Figure 3).

Finally, we use the following MATLAB code to visualize the pure and noise-injected chirp signal in the time domain.

While the time domain visualization is an accurate representation of the signal that will come from the AWG (Figures 4 and 5), it is much easier to verify that the signal is correct from the frequency domain spectrogram plots shown in Figure 3. Note that we normalize the noisy waveform to limit the maximum voltage to ±1 V.

After creating the signal in MATLAB, we create a Quick-Control Function Generator object. We first locate and then connect to the AWG—in our case, an Agilent 33220A Function/Arbitrary Waveform Generator.

To locate the available function generators, we first create an `fgen`

object. We then use the Instrument Control Toolbox `getResources`

function to list the available function generator resources.

`getResources`

returns all resources available to MATLAB. The GPIB resource `GPIB0::10::INSTR`

corresponds to the AWG. We assign the resource string of the AWG to the `Resource`

property of the object.

We can now establish a connection from MATLAB to the AWG.

Once the connection has been established, we can configure AWG settings such as offset and load impedance to suit the application requirements. We need to configure the instrument to output an arbitrary custom waveform from channel 1.

Without Quick-Control Function Generator, it would take many lines of SCPI code or IVI driver code to assign and enable the generation of a custom waveform. With Quick-Control Function Generator it takes a single function call. Further, the same function can be used for any AWG supported by Quick-Control Function Generator.

We close the session and remove it from the workspace, first disconnecting the object and then deleting it from MATLAB memory.

Unlike SCPI commands, which are not always portable, Quick-Control Function Generator lets you reuse the same code to control an AWG from a different manufacturer by changing only the resource string and driver. Quick-Control Function Generator also provides a simple, high-level interface that lets you download a custom waveform to an instrument without having to learn programming with IVI driver or SCPI commands. The MATLAB script can be reused with any instrument that satisfies the requirements of Quick-Control Function Generator, and it can be shared with other engineers and technicians who have a similar workflow.

92074v00