%%More indepth discussions about cross-correlation function close all clear all clc format compact SimpleSignals pause close (1) close (2) close (3) close (4) close (5) % s1: boxcar, s2: spike, s3: triangle, s4: simple wavelet, s5:wavelet+noise %%%%% ns4=length(s4) %21 [cs4,tlag4]=xcov(s4,'unbiased'); n04=find(tlag4==0); cs40=cs4(n04); ns5=length(s5) %100 [cs5,tlag5]=xcov(s5,'unbiased'); n05=find(tlag5==0); cs50=cs5(n05); % cross-correlation between s5 and s4 s4c=zeros(1,length(s5)); s4c(1,1:ns4)=s4(1:ns4); [cov_ec,tlag] = xcov(s5, s4c, 75, 'unbiased'); nop=find(tlag==0); Rcov_ec=cov_ec./cov_ec(nop); figure(1) subplot(2,2,2); plot(s5,'-b') title('inputs') subplot(2,2,4); plot(s4c,'-b') subplot(2,2,[1 3]); plot(tlag,Rcov_ec, '-b') title('output') %%%The cross-covariance is the cross-correlation function of % two sequences with their means removed: % C(m) = E[(A(n+m)-MA)*conj(B(n)-MB)] % where MA and MB are the means of A and B respectively. %In this problem, A is the wavelet in noise, and B is the simple wavelet. % According to the formulation in the program, one would anticpate % maximum cross correlation starting around m=50 to m=70 (about the % length of the wavelet) since the wavelet is embedded in the noise % about 50 lagged-time in A 'after' the simple wavelet is presented in % B. Also, through this way, one can identify the location of the wavelet % embedded in the noise. These are indeed observed.