%
% Test delay estimation with two cases: injected signal or only noise
% 
% M Nofrarias 13-10-09
%
% VERSION:    $Id: test_ao_delayEstimate.m,v 1.1 2009/10/21 08:39:28 miquel Exp $
%
%
%%

close all
clear
A =1;
sigma = 0.01;

% test 1
fs = 2048;
nsecs = 0.75;
sig_f = 256;
sig_d = 2;

% test 2
% fs = 10;
% nsecs = 10;
% sig_f = 1;
% sig_d = 3;

signal = 1;

%%


if signal == 1
  % create white noise, given a known seed
  pl = plist('waveform','noise','nsecs',nsecs,'fs',fs,'sigma',sigma);
  a1 = ao(pl);
  a1.setName('noise')
  
  % create sine wave
  pl = plist('waveform','sine wave','A',A,'f',sig_f,'phi',0,'nsecs',nsecs,'fs',fs);
  a2 = ao(pl);
  
  % add both
  a = a1 +a2 ;
  
  % create white noise, given a known seed
  pl = plist('waveform','noise','nsecs',nsecs,'fs',fs,'sigma',sigma);
  b1 = ao(pl);
  b1.setName('noise')
  
  b2 = delay(a2,plist('n',sig_d));
  
  b =  b1 +b2 ;
else
  % create white noise, given a known seed
  pl = plist('waveform','noise','nsecs',nsecs,'fs',fs,'sigma',sigma);
  a1 = ao(pl);
  a1.setName('noise')
  
  
  % add both
  a = a1 ;
  
  % create white noise, given a known seed
  pl = plist('waveform','noise','nsecs',nsecs,'fs',fs,'sigma',sigma);
  b1 = ao(pl);
  b1.setName('noise')
  
  b = delay(a,plist('n',sig_d));
  
end

iplot(a,b)


%%

pl = plist('weight','scc','plot','true');
d(1) = delayEstimate(a,b,pl);




