【问题标题】:Identify multiple correlations between two signals识别两个信号之间的多重相关性
【发布时间】:2018-05-20 13:18:11
【问题描述】:

我有两个时间信号,每个信号都包含两个相同的脉冲,但位置不同。

描述两个信号的图片:

如何使用 python 获得每个脉冲的两个信号之间的时间偏移? 互相关似乎不是完成这项工作的可靠方法...... 你可以在那里看到互相关函数和我想恢复的两个时移:

如果我们只有一个脉冲,虽然时间偏移是从互相关函数的最大值完美获得的,但您可以看到它在多个脉冲的情况下没有多大帮助。

这是我的测试程序:

import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

N = 200     # Number of points in initial, unshifted signals
N_pad = 500 # Total number of points at the end
t = np.linspace(-1, 1, N) # Dummy time vector
dt = t[1]-t[0] # Time step
Fs = 1.0/dt    # Sampling frequency
pulse1 = signal.gausspulse(t, fc=5) # Create a pulse at 5 Hz
pulse2 = signal.gausspulse(t, fc=8) # Create a pulse at 8 Hz

# Shift and pad the pulses
pulse1_shifted = np.concatenate((pulse1,np.zeros(50)), axis=0)
pulse2_shifted = np.concatenate((pulse2,np.zeros(100)), axis=0)
pulse1_shifted_padded = np.concatenate((np.zeros(N_pad-len(pulse1_shifted)),pulse1_shifted), axis=0)
pulse2_shifted_padded = np.concatenate((np.zeros(N_pad-len(pulse2_shifted)),pulse2_shifted), axis=0)

# Create signal 1 as the sum of the two pulses
sig1 = pulse1_shifted_padded + pulse2_shifted_padded

# Different time shift
pulse1_shifted = np.concatenate((pulse1,np.zeros(60)), axis=0)
pulse2_shifted = np.concatenate((pulse2,np.zeros(150)), axis=0)
pulse1_shifted_padded = np.concatenate((np.zeros(N_pad-len(pulse1_shifted)),pulse1_shifted), axis=0)
pulse2_shifted_padded = np.concatenate((np.zeros(N_pad-len(pulse2_shifted)),pulse2_shifted), axis=0)

# Create signal 2 as the sum of the two pulses
sig2 = pulse1_shifted_padded + pulse2_shifted_padded

# Create new time vector at the same sampling rate
t = np.arange(dt*N_pad,step=dt)

# Plot the two signals
plt.figure()
plt.plot(t,sig1,label="Signal 1")
plt.plot(t,sig2,label="Signal 2")
plt.legend()
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")
plt.title("The two signals. Orange and blue has been recorded at 100 m distance")

# Plot the cross correlation between the two signals
corr = signal.correlate(sig1,sig2)
dt = np.arange(1-N_pad,N_pad)/Fs # Time shift vector
plt.figure()
plt.plot(dt,corr)
plt.plot([0.1,0.1],[-20,20],"--")
plt.plot([0.5,0.5],[-20,20],"--")
plt.ylim([-15,15])
plt.xlabel("Time shift (s)")
plt.ylabel("Cross correlation function")

你有解决办法吗?

非常感谢

【问题讨论】:

  • 如果脉冲具有与您的示例中不同的频率基础分量,那么它们可能更容易被 FFT 分离

标签: python signal-processing cross-correlation


【解决方案1】:

由于互相关与两个脉冲完美配合,因此您可以选择任何一个脉冲作为基线,并与其余脉冲执行成对互相关以确定偏移量作为一种快速解决方法。

【讨论】:

    【解决方案2】:

    如果我理解正确,您需要一种自动化方法来提取互相关响应中橙色和绿色光标之间的时间偏移,例如您在问题中提供的响应。在您的示例中,此时间偏移将是两个脉冲对之间的边际时间偏移。两个脉冲对之间的边际时间偏移(例如您的示例中的那些)可以直接从互相关结果(例如您提供的结果)中推断出来。您可以通过首先检测互相关结果中的局部最大值点来做到这一点。接下来,按幅度降序对局部最大值点进行排序,同时保留与每个局部最大值相关的时间戳。两个脉冲之间的边际偏移将等于与局部最大值排序列表中的前两个局部最大值点相关联的两个时间戳之间的差。

    【讨论】:

      猜你喜欢
      • 2015-02-17
      • 1970-01-01
      • 2017-06-01
      • 2014-03-10
      • 2019-04-03
      • 2012-03-27
      • 2014-01-05
      • 1970-01-01
      • 2012-12-29
      相关资源
      最近更新 更多