function daq_may_2006

daqreset, close all

samples_per_ms=10;
trial_duration_in_seconds=90;
pulse_start_time_in_seconds=20;
pulse_duration_in_seconds=50;
pulsed_channel=2;

sampling_rate=samples_per_ms*1000;
samples_per_trigger=sampling_rate*trial_duration_in_seconds;

d1output=analogoutput('nidaq',1);
addchannel(d1output,0);
addchannel(d1output,1);
set(d1output,'TransferMode','Interrupts')
set(d1output,'TriggerType','Manual')        
set(d1output,'SampleRate',sampling_rate)

d1input=analoginput('nidaq',1);
addchannel(d1input,0);
addchannel(d1input,1);              
set(d1input,'SampleRate',sampling_rate)
set(d1input,'SamplesPerTrigger',samples_per_trigger)
set(d1input,'ChannelSkewMode','Minimum')
set(d1input,'TransferMode','SingleDMA')
set(d1input,'TriggerType','Manual')

output_trains=repmat(0,samples_per_trigger,2);
output_trains((pulse_start_time_in_seconds*sampling_rate)+[1:pulse_duration_in_seconds*sampling_rate],pulsed_channel)=5;

figure(1),plot(output_trains)
set(d1input,'SamplesPerTrigger',5000)

synch=[d1output d1input];
putdata (d1output,[output_trains])
start(synch)
trigger(synch)

[dataa timee]=getdata(d1input);
figure(2),plot([inv(samples_per_ms):inv(samples_per_ms):(length(dataa)/samples_per_ms)],dataa(:,1:2))