现在,我正在对该阵列进行横断面并应用一维 - 巴特沃斯带通滤波器:
import numpy as np
from scipy.signal import find_peaks, butter, sosfiltfilt, sosfreqz
def Transect_angle(A, angle, Sp, length):
x0, y0 = Sp[0], Sp[1]
x1, y1 = x0 + cosd(angle)*length, y0 + sind(angle)*length
return Array_transect(A, [y0,x0], [y1,x1], 'nearest'), [x0,y0], [x1,y1]
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
sos = butter(order, [low, high], analog=False, btype='band', output='sos')
return sos
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
sos = butter_bandpass(lowcut, highcut, fs, order=order)
y = sosfiltfilt(sos, data)
return y
transect, p0, p1 = Transect_angle(Array, angle, start ,length)
tr_withoutnan = transect[~np.isnan(transect)] ### removing nan
filtered = butter_bandpass_filter(tr_withoutnan, low_freq, High_freq, 1)
我想将相同类型的过滤但直接以 2D 形式应用于我的数组。我有两个主要问题:
对我来说,过滤基本上是数据和过滤器之间的卷积。基于此,我可以直接使用具有轴对称性的巴特沃斯滤波器对我的数组进行卷积。但是,在我的函数
butter_bandpass_filter中,我正在使用sosfiltfilt,其中提到过滤器是向前和向后应用的。我不知道它在卷积方面意味着什么,但我记得有人提到它在我很久以前读过的一个主题中很重要。我应该处理 Nans 值(在我的图像中为白色)吗?
最后,我使用了一个巴特沃斯带通滤波器,因为我读到它是最不可能产生伪影的滤波器。我愿意接受任何建议!
