Main Content

使用互相关性对齐信号

许多测量涉及多个传感器异步采集的数据。如果您要集成信号并以关联式研究它们,您必须同步它们。为此,请使用 xcorr

例如,假设有一辆汽车经过一座桥。它产生的振动由位于不同位置的三个相同传感器进行测量。信号有不同到达时间。

将信号加载到 MATLAB® 工作区并进行绘图。

load relatedsig

tiledlayout(3,1)

ax(1) = nexttile;
plot(s1)
ylabel("s_1")

ax(2) = nexttile;
plot(s2)
ylabel("s_2")

ax(3) = nexttile;
plot(s3)
ylabel("s_3")
xlabel("Samples")

linkaxes(ax,"x")

计算三对信号之间的互相关性。将它们归一化,使其最大值为 1。

[C21,lag21] = xcorr(s2,s1);
C21 = C21/max(C21);

[C31,lag31] = xcorr(s3,s1);
C31 = C31/max(C31);

[C32,lag32] = xcorr(s3,s2);
C32 = C32/max(C32);

互相关性最大值的位置指示领先或滞后时间。

[M21,I21] = max(C21);
t21 = lag21(I21);

[M31,I31] = max(C31);
t31 = lag31(I31);

[M32,I32] = max(C32);
t32 = lag32(I32);

绘制互相关图。在每个绘图中显示最大值的位置。

tiledlayout(3,1)

nexttile
plot(lag21,C21)
xline(t21,"-","Lag: "+t21,LabelOrientation="horizontal")
ylabel("C_{21}")
title('Cross-Correlations')

nexttile
plot(lag31,C31)
xline(t31,"-","Lag: "+t31,LabelOrientation="horizontal")
ylabel("C_{31}")

nexttile
plot(lag32,C32)
xline(t32,"-","Lag: "+t32,LabelOrientation="horizontal")
ylabel("C_{32}")
xlabel("Samples")

s2 领先于 s1 350 个样本;s3 落后于 s1 150 个样本。因此,s2 领先于 s3 500 个样本。通过截断具有较长延迟的向量来对齐信号。这些信号现在已同步,可用于进一步处理。

s1 = s1(-t21:end);
s3 = s3(t32:end);

tiledlayout(3,1)
ax(1) = nexttile;
plot(s1)
ylabel("s_1")

ax(2) = nexttile;
plot(s2)
ylabel("s_2")

ax(3) = nexttile;
plot(s3)
ylabel("s_3")
xlabel("Samples")

linkaxes(ax,"x")

另请参阅

| |

相关主题