Pandas.rolling().median vs Scipy.signal.medfilt()

问题描述 投票:0回答:1

我申请了 Pandas.rolling().median()它有一个 拖延相移 (绿线)。

如果我使用 Scipy.signal.medfilt() 的结果是不移位的(黄线)。

enter image description here

为什么,结果不一样?

P.S.我试着研究了一下。医学基金会 的实现,其中使用了sigtools._order_filterND,我猜测它不是在python中。

CODE.Pandas.rolling().median(),我应用了Pandas.rolling().median(),它有延迟或相位偏移(绿线),我认为它不在python中。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import medfilt

x = np.zeros(100)
x[30:70] = 2
x+= .1 * np.random.randn(100)

y1 = medfilt(x, kernel_size=5)

plt.plot(x, '.-', label='original signal');
plt.plot(y1, '.-', alpha=.5, label='medfilt'); 
plt.plot(pd.Series(x).rolling(5).median(), label='rolling window');
plt.legend();

pandas scipy filtering signal-processing smoothing
1个回答
1
投票

你有沒有試過在滾動的時候把窗戶對中?

Pandas.rolling(center=True).median()
© www.soinside.com 2019 - 2024. All rights reserved.