目录
许多测量涉及多个传感器异步采集的数据。如果要集成信号,必须同步它们。Signal Processing Toolbox™ 提供的一些函数可实现此目的。
例如,假设有一辆汽车经过一座桥。它产生的振动由位于不同位置的三个相同传感器进行测量。信号有不同到达时间。
将信号加载到 MATLAB® 工作区并进行绘图。
- load relatedsig
-
- ax(1) = subplot(3,1,1);
- plot(s1)
- ylabel('s_1')
-
- ax(2) = subplot(3,1,2);
- plot(s2)
- ylabel('s_2')
-
- ax(3) = subplot(3,1,3);
- plot(s3)
- ylabel('s_3')
- xlabel('Samples')
-
- linkaxes(ax,'x')
如图所示:

信号s1落后于s2,但领先于 s3。可以使用finddelay精确计算延迟。可以看到,s2 领先于 s1 350 个样本,s3落后于 s1 150 个样本,而 s2 领先于 s3 500 个样本。
- t21 = finddelay(s2,s1)
- t31 = finddelay(s3,s1)
- t32 = finddelay(s2,s3)
-
-
- t21 =
-
- 350
-
-
- t31 =
-
- -150
-
-
- t32 =
-
- 500
通过保持最早的信号不动并截除其他向量中的延迟来对齐信号。滞后需要加 1,因为 MATLAB® 使用从 1 开始的索引。此方法使用最早的信号到达时间(即 s2 的到达时间)作为基准来对齐信号。
- axes(ax(1))
- plot(s1(t21+1:end))
-
- axes(ax(2))
- plot(s2)
-
- axes(ax(3))
- plot(s3(t32+1:end))
如图所示:

使用 alignsignals 对齐信号。该函数会延迟较早的信号,以使用最晚的信号到达时间(即 s3 的到达时间)作为基准。
- [x1,x3] = alignsignals(s1,s3);
- x2 = alignsignals(s2,s3);
-
- axes(ax(1))
- plot(x1)
-
- axes(ax(2))
- plot(x2)
-
- axes(ax(3))
- plot(x3)
如图所示:

这些信号现在已同步,可用于进一步处理。
有时数据会出现不必要的瞬变(即峰值)。中位数滤波是消除它的好方法。
以存在 60 Hz 电线噪声时模拟仪器输入的开环电压为例。采样率为 1 kHz。
- load openloop60hertz
-
- fs = 1000;
- t = (0:numel(openLoopVoltage) - 1)/fs;
通过在随机点添加随机符号以加入瞬变以破坏信号。重置随机数生成器以获得可再现性。
- rng default
-
- spikeSignal = zeros(size(openLoopVoltage));
- spks = 10:100:1990;
- spikeSignal(spks+round(2*randn(size(spks)))) = sign(randn(size(spks)));
-
- noisyLoopVoltage = openLoopVoltage + spikeSignal;
-
- plot(t,noisyLoopVoltage)
-
- xlabel('Time (s)')
- ylabel('Voltage (V)')
- title('Open-Loop Voltage with Added Spikes')
如图所示:

yax = ylim;
函数 medfilt1 将信号的每个点替换为该点和指定数量的邻点的中位数。因此,中位数滤波会丢弃与其周围环境相差很大的点。通过使用三个邻点的集合计算中位数来对信号进行滤波。注意峰值是如何消失的。
- medfiltLoopVoltage = medfilt1(noisyLoopVoltage,3);
-
- plot(t,medfiltLoopVoltage)
-
- xlabel('Time (s)')
- ylabel('Voltage (V)')
- title('Open-Loop Voltage After Median Filtering')
- ylim(yax)
- grid
如图所示:
