當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy signal.correlation_lags用法及代碼示例

本文簡要介紹 python 語言中 scipy.signal.correlation_lags 的用法。

用法:

scipy.signal.correlation_lags(in1_len, in2_len, mode='full')#

計算一維互相關的滯後/位移 index 數組。

參數

in1_len int

第一個輸入大小。

in2_len int

第二個輸入大小。

mode str {‘full’, ‘valid’, ‘same’},可選

指示輸出大小的字符串。有關詳細信息,請參閱文檔 correlate

返回

lags 數組

返回一個包含互相關滯後/位移 index 的數組。可以使用相關性的np.argmax 對索引進行索引,以返回滯後/位移。

注意

連續函數 的互相關定義為:

其中 定義為位移,也稱為滯後。

離散函數 的互相關定義為:

其中 是滯後。

例子

信號與其time-delayed 自身的互相關。

>>> import numpy as np
>>> from scipy import signal
>>> rng = np.random.default_rng()
>>> x = rng.standard_normal(1000)
>>> y = np.concatenate([rng.standard_normal(100), x])
>>> correlation = signal.correlate(x, y, mode="full")
>>> lags = signal.correlation_lags(x.size, y.size, mode="full")
>>> lag = lags[np.argmax(correlation)]

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.signal.correlation_lags。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。