%MacDAQ.m
clear all;
t=[0:0.0001:0.5]; %analog time
fs=400; %sampling Frequency, Hz
N=160; %sample points
ts=[0:1/fs:N/fs]; %sampled time
freq1=10;
freq2=20;
freq3=40;
freq4=80;
amp1=1; amp2=0.5; amp3=0.25; amp4=0.125;
%construct the analog signal
sine1=amp1*sin(2*pi*freq1*t);
sine2=amp2*sin(2*pi*freq2*t);
sine3=amp3*sin(2*pi*freq3*t);
sine4=amp4*sin(2*pi*freq4*t);
noise=amp4*rand(1,size(t,2));
signal=sine1+sine2+sine3+sine4+noise;
%Construct the discrete signal 
dis_sine1=amp1*sin(2*pi*freq1*ts);
dis_sine2=amp2*sin(2*pi*freq2*ts);
dis_sine3=amp3*sin(2*pi*freq3*ts);
dis_sine4=amp4*sin(2*pi*freq4*ts);
dis_noise=amp4*rand(1,size(ts,2));
dis_signal=dis_sine1+dis_sine2+dis_sine3+dis_sine4+dis_noise;
%create a text file of the sampled signal called CompositeSine for export
figure(1), plot(t,signal,'k',ts,dis_signal,'o');
grid on
fid=fopen('CompositeSine.txt','w');
fprintf(fid,'%6.4f\r',dis_signal);
fclose(fid);