MATLAB 中用于同步的自动或互相关

信息处理 matlab 连续信号
2022-02-03 21:56:02

我有多个电机声音记录,我想先同步它们,然后计算它们的频谱图。我的问题是如何使用自相关或互相关来同步它们?我想确保我在频谱图中看到的唯一区别与频率有关,而不是与电机的起始位置或记录有关。

我知道在 MATLAB 中计算自相关和互相关,但我不明白如何将它们用于同步目的。

谢谢你的帮助!

1个回答

大多数情况下,这是一项非常简单的任务。这是移位正弦曲线的示例:

t = linspace(0,6*pi,1000); % time vector for sinusoid
s = [zeros(1,100), sin(2*pi*t), zeros(1,100)];  % original signal
shift = 30; % we are shifting our sinusoid 30 bins to the right
ss = [zeros(1, shift) s(1:end-shift)]; % signal shifted
subplot(2,1,1)
plot(s); hold on;
plot(ss, 'r')

[c, lags] = xcorr(ss, s); % get the cross-correlation together with lags
subplot(2,1,2)
plot(lags, c)

pred_shift = lags(c==max(c)); % calculated the shift from maximum value of cross-correlation

输出是:30你可以用它来移回信号ss在您的引擎信号的情况下,它将是类似的。