简体   繁体   English

两个信号之间的互相关是否受缩放影响?

[英]Is cross-correlation between two signals affected by scaling?

By my understanding, translations and scaling do not affect the correlation between two series.据我了解,平移和缩放不会影响两个系列之间的相关性。 However, I'm using the correlate function by from the scipy python library and the MinMaxScaler from the sklearn library and I get totally different results for the cross-correlation of 2 series before and after scaling them to [-1, 1].但是,我正在使用来自 scipy python 库的相关值 function 和来自 sklearn 库的 MinMaxScaler,在将它们缩放到 [-1, 1] 之前和之后,我得到了 2 个系列的互相关的完全不同的结果。 The plots of the two different cross-correlations can be seen on the attached image!可以在附图中看到两种不同互相关的图!

在此处输入图像描述

Is my assumption that scaling does not affect the correlation wrong?我假设缩放不影响相关性是错误的吗?

Thanks!谢谢!

MinMaxScaler maps data between (min, max) , which can change the DC offset and (consequently) polarity of a signal (but not frequency); MinMaxScaler(min, max)之间映射数据,这可以改变信号的直流偏移和(因此)极性(但不是频率); cross-correlation responds strongly to both these traits.互相关对这两个特征都有强烈的反应。 To illustrate, a rising sine:为了说明,一个上升的正弦:

import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sig
from sklearn.preprocessing import MinMaxScaler

#%%##########################################################
x = np.linspace(0, 5, 60)  # [0, 0.084, 0.169, ..., 4.91, 5]
x = x.reshape(-1, 1)       # (samples, features) = (60, 1)
y = x + np.sin(x)          # rising sine above x-axis
y_scaled = MinMaxScaler((-1, 1)).fit_transform(y)

#%%##########################################################
plt.plot(y)
plt.plot(y_scaled)
plt.axhline(0, color='k', linestyle='--')
plt.show()
#%%#####################################
plt.plot(sig.correlate(x, y))
plt.plot(sig.correlate(x, y_scaled))
plt.show()

I did say "can";我确实说了“可以”; the condition for not changing cross-correlation shape is for neither polarity nor DC offset to change between transforms - ie the transform can be obtained purely by scaling.改变互相关形状的条件是极性和直流偏移都不会在变换之间改变——即变换可以纯粹通过缩放获得。 Eg sin(x)/2 -> sin(x).例如 sin(x)/2 -> sin(x)。

I recommend chapters 6 & 7 of this textbook , which present an excellent intuitive explanation of convolution, and then cross-correlation.我推荐这本教科书的第 6 章和第 7 章,其中对卷积和互相关进行了出色的直观解释。 There's also an interactive illustration.还有一个交互式插图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM