开发者

Matching two vectors of different length in MATLAB

I have data from two different sensors loaded into two separate vectors. These sensors measure the same acceleration and hence their pattern is the same. However, because of measurement noise, the values will be slightly different for both. Also, because of the different sampling frequency and delays etc, the length of one vector will be bigger than the length of the other.

My question is, how do I equate these two vectors. That is, I nee开发者_StackOverflowd to find the reading in vectorA that corresponds to a particular reading in vectorB. I tried to compare the extrema using the findpeaks() function, but I'm not sure how exactly to go about it.

Thanks!


There is no way to "match" them without the original sample rates. This is because the data is actually both the time and the magnitude. If you leave out the time you can't tell when the sample occurred and hence you can't know if it's different from the other that occurred(cause it might have occurred at a different time).

Now, if the data is relatively close you might be able to estimate the relative different in sample frequency and use that to resample but depending on the accuracy of your sampling it might not work well.

Can you assume that the sample rates are close and approximately constant?

What you are looking to do is minimize the function

int(||f(r*t) - g(t)||^2) over r.

Essentially scaling f's time axis until it "matches" g's. If the same rate is not constant then r is a function of t. This makes the problem intractable since the min is likely not to be unique(although with some minimum bounded variation of r it might).

For example, what you can do is compute that expression for various r and attempt to find a minimum for some range of r. If the expression is not within some bound you can reject it as "matching".

You can get more advanced such as using a Kalman filter to attempt to narrow down the result even more.

It's really going to depend on how accurate your data is and how accurate you want your result(is a false positive going to kill anyone?).

Because you say it's suppose to be the same data you do have a starting point ans this should get you a unique r in the minimization problem above. You're going to have to assume that the sample rate is approximately constant though(or adapt the minimization problem).

Maybe the better way is to try to get the sampling rate/time points instead? (then the matter becomes almost trivial).


Assuming you can collect some data, you could calibrate for the sampling frequencies of both sensors. For two accelerometers, that could mean doing something strange like taping the phone to the inside wall of a bucket, then rolling it along the floor. If you look at the resulting data, you should have a correlated signal from both sensors. Taking FFT's of both sets of sensor data will allow you to see how the sampling rates can be matched. The offset in period could be accounted for by having a sudden acceleration event, like dropping the phone onto a pillow or folded blanket.

Once the sampling frequencies of the two sensors are calibrated, then you can interpolate between the two of them to have matched vectors. Unfortunately, this won't help if the sensors are initialized in arbitrary ways relative to each other. In a multitasking OS with independent peripherals, this approach might not be very fruitful for getting the offset between the two traces. But it should at least help you to know what the sampling rates of each sensor. If the signals are resampled to the same rate, then taking a convolution (as suggested above) should allow you to determine the offset in real-time from collected data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜