I tried to align two signal better using the below code. The s1 and s2 is in the attached txt file. However, td I got is -24482. I am wondering if there is a way to improve this function. Please help!!
function [td,ny]=align_signal(s1,s2)ny=ones(size(s1))*NaN;[C21,lag21] = xcorr(s2,s1);C21 = C21/nanmax(C21);[M21,I21] = nanmax(C21);t21 = lag21(I21);if t21<0 ny(-t21:end) = s1(-t21:end);else ny(t21:end)=s1(t21:end);endtd=abs(t21);
Best Answer