views:

100

answers:

2

Hi,

I have two waveforms which are linked by a numerical factor. I need to use optimal scaling (least squares) between the two waveforms to calculate this factor in Matlab. Unfortunately I have no idea how to do this. The two wave forms are seismic signals related by the velocity of the seismic waves, which I'm trying to calculate. Any ideas? need more info?

Thanks

Jon.

+1  A: 

Call W1 and W2 the two vectors. For this to work, they must be column vectors. Transpose them if they are rows instead of columns. Then if we wish to find the value of k such that W1 = k*W2, just use backslash.

k = W2\W1;

Backslash here gives you a linear regression (least squares) estimator, as requested. This does not handle the unknown phase shift case of course.

woodchips
Is there a limit on the ability of this equation as an estimator? I am expecting values of 2500-4000 but this method gives me a value of 0.9913. I can get closer to my expected value by dividing single values from the two column vectors. I've just thought as well, sometimes the signal to noise ratio is extremely low, meaning the waves will be completely out of phase. I will have to limit the equation to high S/N areas only.
Jon
Sorry I got the equation wrong. I have now corrected it but I am still getting a wide varying result when I use this on small segments of the waveforms, and the results I am expecting are supposed to be quite linear.
Jon
if you want an *affine* transform, you have to include an intercept term: `betas = [ones(numel(W2),1),W2(:)] \ W1(:)`, after which `W1` is approximately `betas(1) + betas(2) * W2`;
shabbychef
If the signals are out of phase, then you might see problems, as then the two signals will be orthogonal. However it is very unlikely that the two are virtually 90 degrees out of phase, especially since you said that this was not a significant factor. Are these COLUMN vectors as I indicated was necessary? If you are unsure, then use k=W2(:)\W1(:);
woodchips
+1  A: 

one cheesy way to estimate the linear factor without having to deal with phase shift is to compute the ratio of the estimated scales of the waves. the cheesiest way is to use standard deviation:

k = std(W1) / std(W2);

if you care about robustness, I would substitute in the MAD or the IQR; the MAD is the median absolute deviation, which you can (somewhat inefficiently) 'inline' as so:

MAD = @(x)(median(abs(bsxfun(@minus,x,median(x)))));
k = MAD(W1) / MAD(W2);

the IQR is the interquartile range, which requires a proper quantile computation. you can implement this inefficiently using sort. I leave this as an exercise to the reader.

shabbychef
BTW, this kind of stuff is *the* bread and butter of pulse oximetry. If you run out of ideas, check the PO literature, or look through the patents being spewed out by Nellcor and Massimo.
shabbychef