clear; daqreset;    %% start clean

%%% Parameters for the experimens
T = 2;          %% length of experiment
sr = 2000;      %% Samples per second
Ns = T*sr;      %% Total number of samples 

%%% analoginput configuration, set rates, channels, etc
ai = analoginput('nidaq','Dev1');
addchannel(ai,[0 1 2 3]);
set(ai,'SampleRate',sr);
set(ai,'SamplesPerTrigger',Ns)

%%% Collect the data
start(ai);      %%% Start the engine  - trigger on start
wait(ai,T+2);   %%% wait for collection to be over before moving on
[data time] = getdata(ai);  %%% move data from the DAQ to workspace


%%%% Plot the data
plot(time,data(:,1),'b'); hold on;
plot(time,data(:,2),'r');
plot(time,data(:,3),'k');
plot(time,data(:,4),'m');
legend('ch0', 'ch1','ch2','ch3')
hold off;