Skip to content

Instantly share code, notes, and snippets.

@npyoung
Created November 3, 2016 23:34
Show Gist options
  • Save npyoung/bc12420401f21ab03c3326cb88843755 to your computer and use it in GitHub Desktop.
Save npyoung/bc12420401f21ab03c3326cb88843755 to your computer and use it in GitHub Desktop.
Play a tone periodically and output an analog sync signal in Matlab
% params
interval = 10;
f = 2800;
fs = 8192;
dur = 2;
% Generate waveforms
t = 0:1/fs:dur;
tone = sin(2 * pi * f * t);
% Set up the analog output
s = daq.createSession('ni');
daq.getDevices();
device = devices(1);
ch = s.addAnalogOutputChannel(device.ID, 0, 'Voltage');
s.Rate = 100;
% Start outputting
while true
s.outputSingleScan([5]);
sound(tone, fs);
pause(dur);
s.outputSingleScan([0]);
pause(interval - dur);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment