| Data Acquisition Toolbox | Search  Help Desk |
Outputting Data with a Sound Card
In this example, sine wave data is generated in MATLAB, output to the D/A converter on the sound card, and sent to a speaker. The setup is shown below.
putdata calls, and a manual trigger is issued to initiate the output. The complete data acquisition session for the sound card is shown below.
Initialization: Create the analog output object AO for a sound card. The installed adaptors and hardwrae ID's are found with daqhwinfo.
AO = analogoutput('winsound');
Configuration: Add one channel to AO, define an output time of four seconds, assign values to the basic setup properties, generate data to be queued, and queue the data with one call to putdata.
Termination: Deletechans = addchannel(AO, 1);duration = 4;set(AO, 'SampleRate', 8000);set(AO, 'TriggerType', 'Manual');set(AO.Channel(1), 'UnitsRange', [-2 2]); ActualRate = get(AO, 'SampleRate'); len = ActualRate*duration; data = 2*sin(linspace(0, 2*pi, len))'; putdata(AO, data); Execution: StartAO, issue a manual trigger, and wait for the device object to stop running.
AO.
delete(AO)
Note:
AO before queueing data with the first putdata call.