Created
November 3, 2016 23:34
-
-
Save npyoung/bc12420401f21ab03c3326cb88843755 to your computer and use it in GitHub Desktop.
Play a tone periodically and output an analog sync signal in Matlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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