repeat analog output with DAQ at fast rates
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to read in an external trigger and ouput a sine wave everytime an exteral trigger is recieved. I have tried using both the session based interface, and the legacy based interface (for 32 bit Matlab). I have been able to continuiously output the signal via repeat output (for session based interface) and using putdata / start / wait functions within a loop for the legacy based interface. Both methods work, but only if the trigger is presented slow enough (e.g. ~ 2-3 Hz). Any faster, then Matlab starts missing triggers and the signal is not output on every trigger. It would be great if I can present much faster (~80Hz) without missing triggers. Here is my code for reference.
% stimulus properties
duration=0.01; % 10 ms
frequency=500;
Rate=44100;
step=1/Rate;
t=(0:step:duration);
OutputWave=sin(2*pi*frequency*t)';
x=size(OutputWave);
w=blackman(88); %set rise-fall to 1 ms
OutputWave(1:44)=OutputWave(1:44).*w(1:44);
OutputWave(x(1)-43:x(1))=OutputWave(x(1)-43:x(1)).*w(45:88);
plot(OutputWave); xlabel('Time'); ylabel('Voltage');
% create AO
AO = analogoutput('nidaq','Dev1')
chan = addchannel(AO,0);
set(AO,'SampleRate',Rate);
set(AO,'TriggerType','HwDigital');
AO.HwDigitalTriggerSource = 'PFI0';
set(AO,'TriggerCondition','PositiveEdge')
waitTime = (length(OutputWave)/Rate)+.6;
% adding .6 waitTime slows us to ~ 1.5 Hz
noOfSweeps = 100;
for i = 1:noOfSweeps
putdata(AO,OutputWave)
start(AO)
wait(AO,waitTime)
end
2 Kommentare
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!