Data Acquisition Toolbox | ![]() ![]() |
If you have a sound card installed, you can run the following example, which outputs 1 second of data to two analog output hardware channels.
You should modify this example to suit your specific application needs. If you want detailed information about outputting data, refer to Chapter 6, Analog Output.
1. Create a device object - Create the analog output object ao
for a sound card.
ao = analogoutput('winsound');
2. Add channels - Add two hardware channels to ao
.
addchannel(ao,1:2);
3. Configure property values - Configure the sampling rate to 44.1 kHz for each channel.
set(ao,'SampleRate',44100)
4. Output data - Create 1 second of output data, and queue the data in the engine for eventual output to the analog output subsystem. You must queue one column of data for each hardware channel added.
data = sin(linspace(0,2*pi,44100)'); putdata(ao,[data data])
Start the output. When all the data is output, ao
automatically stops executing.
start(ao)
Block the MATLAB command line until ao
stops running.
while strcmp(ao.Running,'On') end
5. Clean up - When you no longer need ao
, you should remove it from memory and from the MATLAB workspace.
delete(ao) clear ao
![]() | Acquiring Data | Reading and Writing Digital Values | ![]() |