Generate Signals with the Analog Output Generator

This topic shows how to use the Analog Output Generator app to define and generate signals from an audio device.

To open the Analog Output Generator, on the MATLAB® Toolstrip, on the Apps tab, in the Test and Measurement section, click the Analog Output Generator.

Upon opening, the Analog Output Generator attempts to find all your attached analog and audio output devices.

Note

Opening the Analog Output Generator deletes all your existing data acquisition sessions in MATLAB.

The data acquisition session created by the Analog Output Generator is not accessible from the MATLAB command line.

If you plug in a device while the app is open, you must refresh the listing for access to the device. On the Devices tab, click Refresh. Use the same procedure to remove a device from the listing after unplugging it.

Select the device you want to use in the Device List. By default, the app immediately displays a preview of a test signal.

Use the following steps to produce an audio output of the "Hallelujah" chorus from Handel's Messiah.

  1. Select the device for your output. This might be the primary sound driver, speakers, or a headset.

  2. Load the sound data into the workspace with the following command in MATLAB:

    load handel

    This loads two variables into your workspace. The sound data is contained in the variable y. The sampling rate is contained in the variable Fs. You will need to know the sampling rate, so display its value.

    Fs
    8192
  3. In the Analog Output Generator, select Workspace Variable. In the adjacent selection list, choose y. This indicates the source of the data for the generator to output.

  4. Enter the Fs value of 8192 in the Rate text box in the Analog Output Generator. This indicates the sampling rate. The apps should now look something like this.

  5. Click Generate to produce the sound output.

If you were successful in producing a sound output, try experimenting with some of the settings in the app. For example, modify the Rate value or the Number of Cycles.

Tip

If you could not hear any sound, use the Test Signal option to generate a constant tone. Check all your hardware connections and different devices in the app until you hear the tone.

In the Analog Output Generator, click Generate Script for the app to open the MATLAB editor and display the code for producing the signal. The code is generated for the finite (non-continuous) output of this example. Notice that this code uses the startForeground function; a continuous output would use startBackground.

See Also

Apps

Related Topics