在 MATLAB 中匹配两个不同长度的向量

发布于 2024-10-13 12:01:22 字数 231 浏览 9 评论 0原文

我将来自两个不同传感器的数据加载到两个单独的向量中。这些传感器测量相同的加速度,因此它们的模式是相同的。然而,由于测量噪声的原因,两者的值会略有不同。另外,由于采样频率和延迟等不同,一个向量的长度会大于另一个向量的长度。

我的问题是,如何将这两个向量等同起来。也就是说,我需要找到与向量 B 中的特定读数相对应的向量 A 中的读数。我尝试使用 findpeaks() 函数来比较极值,但我不确定具体如何进行。

谢谢!

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 need 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

成熟的代价 2024-10-20 12:01:22

如果没有原始采样率,就无法“匹配”它们。这是因为数据实际上既是时间又是幅度。如果省略时间,您将无法判断样本何时发生,因此您无法知道它是否与发生的其他样本不同(因为它可能发生在不同的时间)。

现在,如果数据相对接近,您可能能够估计采样频率的相对差异并使用它来重新采样,但根据采样的准确性,它可能不会很好地工作。

您能否假设采样率接近且近似恒定?

您要做的就是最小化

r 上的函数 int(||f(r*t) - g(t)||^2) 。

本质上是缩放 f 的时间轴,直到它“匹配”g 的时间轴。如果相同的速率不是恒定的,则 r 是 t 的函数。这使得问题变得棘手,因为最小值可能不是唯一的(尽管 r 的一些最小有界变化可能是唯一的)。

例如,您可以做的是计算各种 r 的表达式,并尝试找到 r 的某个范围的最小值。如果表达式不在某个范围内,您可以将其拒绝为“匹配”。

您可以获取更高级的信息,例如使用卡尔曼滤波器来尝试进一步缩小结果范围。

这实际上取决于您的数据有多准确以及您想要的结果有多准确(误报会杀死任何人吗?)。

因为你说它应该是相同的数据,所以你确实有一个起点,这应该在上面的最小化问题中为你提供一个唯一的 r 。不过,您必须假设采样率大致恒定(或适应最小化问题)。

也许更好的方法是尝试获取采样率/时间点? (那么事情就变得几乎微不足道了)。

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).

沧桑㈠ 2024-10-20 12:01:22

假设您可以收集一些数据,您可以校准两个传感器的采样频率。对于两个加速度计,这可能意味着做一些奇怪的事情,比如将手机粘在桶的内壁上,然后沿着地板滚动。如果查看结果数据,您应该会看到来自两个传感器的相关信号。对两组传感器数据进行 FFT 可以让您了解采样率如何匹配。周期的偏移可以通过突然的加速事件来解释,例如将手机掉落到枕头或折叠的毯子上。

一旦校准了两个传感器的采样频率,您就可以在两个传感器之间进行插值以获得匹配的矢量。不幸的是,如果传感器以任意方式相对于彼此初始化,这将无济于事。在具有独立外设的多任务操作系统中,这种方法对于获取两条迹线之间的偏移量可能不太有效。但它至少应该帮助您了解每个传感器的采样率。如果信号以相同的速率重新采样,那么进行卷积(如上所述)应该可以让您根据收集的数据实时确定偏移量。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文