%   ShiftTest.m

%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION. 


a=zeros(100,1);
b=zeros(100,1);

a(49)=.5
a(51)=.5



a(50)=1
b(79)=.5
b(81)=.5
b(80)=1
MaxXCorrVec=xcorr(a,a)'
XCorrVec=xcorr(a,b)'
figure
plot(a)
hold on 
plot(b,'r')
plot(MaxXCorrVec)
plot(XCorrVec,'r')

[MaxMaxXCorr,MaxMaxXCorrInd]=max(MaxXCorrVec)
[MaxXCorr,MaxXCorrInd]=max(XCorrVec)

Shift1=1.5.*MaxMaxXCorrInd-MaxXCorrInd

a(50)=1
b(9)=.5
b(11)=.5
b(10)=1
MaxXCorrVec=xcorr(a,a)'
XCorrVec=xcorr(a,b)'
figure
plot(a)
hold on 
plot(b,'r')
plot(MaxXCorrVec)
plot(XCorrVec,'r')

[MaxMaxXCorr,MaxMaxXCorrInd]=max(MaxXCorrVec)
[MaxXCorr,MaxXCorrInd]=max(XCorrVec)

Shift1=Shift1
Shift2=1.5.*MaxMaxXCorrInd-MaxXCorrInd