Generate Signals with 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 Analog Output Generator.
Upon opening, the Analog Output Generator attempts to find all your attached analog and audio output devices.
Opening the Analog Output Generator deletes all your existing DataAcquisition interfaces in MATLAB.
The DataAcquisition interface 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 that 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.
Select the device for your output. This might be the primary sound driver, speakers, or a headset.
Load the sound data into the workspace with the following command in MATLAB:
This loads two variables into your workspace. The sound data is contained in array named
y. The sampling rate is contained in the variable
Fs. You will need to know the sampling rate, so display its value.
In the Signal Type section of the Analog Output Generator toolstrip, select Workspace Variable. In the adjacent selection list, choose
y. This indicates the source of the data for the generator to output.
8192in the Rate text box in the Analog Output Generator. This indicates the sampling rate. The app should now look something like this.
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.
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.