% DAQ_out
% Generate a cosine
%clear all
close

% Generate a cosine
Fs = 44100;  		% sample rate
f = 200;    		% frequency
dur = 2;     		% duration (seconds)
t = 0:dur*Fs;   	% time index
a = 0.08;    		% amplitude   			-   You will need to set this so clipping doesn't occur
y = a*cos(2*pi*f*t/Fs);

%specgram(y,[],Fs)    %  look at spectrum



% Data acquistion toolbox functions

ao = analogoutput('winsound');   	% create output sound object
addchannel(ao,1:2);					   % add channel 1 to sound object
set(ao,'SampleRate',Fs)					% set sample rate
%get(ao)										% look at channel properties

ai = analoginput('winsound');				% create input sound object
addchannel(ai,1:2);							% add channel 2 to sound object
set(ai,'SampleRate',Fs);					% set sample rate
set(ai,'SamplesPerTrigger',length(y)); % set number of samples to record

putdata(ao,[y(:) y(:)])				% load output data
start(ai)								% start recording
start(ao)								% start outputting
while strcmp(ao.Running, 'on')   % loop while data goes out
end
z = getdata(ai);						% get the data recorded

pause(1);
delete(ai)								% get rid of sound object
delete(ao)                       % get rid of sound object

figure
% Ross:  plot(y(1000:1300)/max(y),'r'); hold on			% compare signal out with signal recorded.
% Ross:  plot(z(1000:1300,1)/max(z(:,1)),'b')
plot(y(1000:1300)/max(y(1000:1300)),'r'); hold on			% compare signal out with signal recorded.
plot(z(1000:1300,1)/max(y(1000:1300)),'b')





