我有两个信号(T0和T1),并想将它们相减:

本质上,红色图形包含一个新的信号(左边的尖峰),我想通过从红色图形中减去蓝色图形来获得这个信号。这个使用互相关的代码几乎每次都适用于我,除了下面这个例子:
% find cross-correlation
[acor,lag] = xcorr(T1,T0);
[~,I] = max(abs(acor));
lagDiff = lag(I);
% shift T0 to T1
T0_shifted = circshift(T0,lagDiff);
% stretch T0, so that it meets the height of T1
T0_shifted = T0_shifted * max(T1)/max(T0_shifted);信号被转移到不需要的位置,因为xcorr()在正确但不需要的位置返回最大值:

有没有办法“调整”xcorr()或任何替代方法来对齐图形?
发布于 2018-03-08 04:57:25
我的答案是假设位置和/或高度与你的理想适合度有很大关系,希望这能给你一些新的想法。
我建议您查看acor输出信号,找出高于某个阈值的峰值实例,并对这些峰值周围的移位信号进行一些类似的高度检测,而不是仅仅使用绝对最大值。如下所示:
[acor, lag] = xcorr(T1, T0);
[pks, locs] = findpeaks(acor);
dHeights = zeros(1, length(locs));
for i = 1:length(locs)
T0_shifted = circshift(T0, lag(locs(i)));
% Sum of absolute differences on the entire signal might be good enough
dHeights = sum(abs(T0_shifted - T1));
end
% Index of minimum value in dHeights corresponds to indexing in pks and locs
[~, I] = min(dHeights);
% To find the actual lag value, find the location of the acor value matching the pks value
lagDiff = lag(acor == pks(I)));如果您只关心定位,则还可以通过执行以下操作在xcorr中指定允许的延迟范围:
trLags = 20; % Limits lag range to [-20, 20]
[acor,lag] = xcorr(T1,trLags);另外,我注意到你正在考虑做max(acor)的显著负相关,这将匹配凹凸尖峰,它们是彼此的镜像-我相信这不是你想要的。
https://stackoverflow.com/questions/49090052
复制相似问题