views:

43

answers:

1

Dear all,

I would like to know if there is a least squares routine in Matlab to scale a template signal to a measured signal in time. Let's say my template is a signal of approx. 1 second, but the corresponding part in the measurement is 1.2 seconds. Now I want to scale my template to be 1.2 seconds long as well. Of course it is possible to simply rescale the template in several steps, cross-correlate with the signal for each step and find the maximum. This however would slow down my programme drastically. Matlab's lsqcurvefit needs two vectors of equal length, and the length of one of the vectors is exactly what I want to vary. Does anyone have an idea? Thanks!

A: 

Have you actually tried the simple fminsearch function approach? It might not be as slow as you think.

e.g. (untested - just for illustration)

x=template; y=data;
fn=@(p)sum(( x(:)-y( 1+max(0,min(length(y),floor([0:(length(x)-1)]-p(1)).*p(2))) ) ).^2)
b=fminsearch(fn,[0 1]); % [offset, scale]

you'll probably need to tweak the limits etc!

It it doesn't suit, you could also look at the CPM toolbox (though it may be too sophisticated for your needs) http://www.cs.toronto.edu/~jenn/alignmentStudy/

Sanjay Manohar