clear; daqreset; clf; figure(1);

%%% parameters for the experiment
sample_rate = 44100;  
plot_duration = 1/2;   %% how frequent to plot
exp_duration = 10;   %% how long to collect data for

%%% Set up the parameters to acquire the data
AI = analoginput('winsound',0);    
chan = addchannel(AI,1);
set(AI,'SampleRate',sample_rate);
set(AI,'SamplesPerTrigger',inf);

start(AI);
N = ceil(exp_duration/plot_duration);
for i =1:N
    
    while AI.SamplesAvailable < sample_rate*plot_duration   %% wait until enough data
    end 
    [data time] = getdata(AI,(sample_rate*plot_duration));  %% get the data  

     plot(time,data);             
     xlabel('t (sec)'); ylabel('V');
     axis([min(time) max(time) -.1 .1])
         
     drawnow;
     
end
