Numpy實現Matlab的xorr函式
阿新 • • 發佈:2020-12-09
技術標籤:Python
廢話不多說,直接上程式碼
def AutoCorrelation(x, lags):
N = len(x)
auto_corr = np.correlate(x, x, mode = 'full')
assert N >= lags - 1
auto_corr = auto_corr[N - lags - 1 : N + lags]
auto_corr = auto_corr / np.max(auto_corr)
return auto_corr
測試一下
a = np.array([1, 2, 3, 4, 5, 6]) print(AutoCorrelation(a, 2))
輸出為:
用Matlab跑一下