%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Main function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pulseOx_template()
daqreset;

%%% parameters for the experiment
sample_rate = 22050;  
duration = 10;   %% how long to collect data

%%% Set up the parameters to acquire the data
AI = analoginput('nidaq','Brian');    
chan = addchannel(AI,[0]);
set(AI,'SampleRate',sample_rate);
set(AI,'SamplesPerTrigger',sample_rate*duration);
set(AI.Channel(1),'InputRange',[-5 5]);
set(AI,'TriggerType','manual')


%%% create data to sound card, this signal will drive the LED
%%% You will need to modifiy to drive the two stereo channels
%%% at different frequencies. 
Fs = 44100;
t = linspace(0,duration,Fs*duration )';
y1 = sin(2*pi*500*t);
y2 = sin(2*pi*500*t);

%%% start the experiment
start(AI);
trigger(AI);            %% starting collecting data on the DAQ
soundsc([y1 y2 ],Fs);   %% send the data to the sounds card


[data time] = getdata(AI);  %% get the dataa

figure(1); clf;
plot(time,data);  xlabel('t (sec)'); ylabel('V (Volts)');
title('Raw photodiode output')

%%% detect data on channel 1 photodiode
data_ch1_500  = detection(data(:,1),time,500)


%%% you will need to add the detection at the other freq.
%%% you will need to add the detection of the other photodiode channel

%%% you will need to add some plotting
%%% you might want to save the raw data in case you like the data
%%%    but not the way you processed it. 

delete(AI);
clear AI;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Detection function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data_detect = detection(data,time,f)
data_detect = zeros(size(data));  %% allocate the data output


%%% you need to write this function - see the lab writeup

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Low-pass filter function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data_lp = low_pass(data,alpha)
data_lp = zeros(size(data));   %% allocate the data output

%%% you need to write this function - see the lab writeup

end