这里我调用了两次bandpass函数,实现对原数据进行带通滤波,目的是得到从一个原数据data中得到三个不同频带的数据,但是结果出来却相同的并且是错的,而这三个各自单独调用一次(即注释掉另外两个bandpass的调用)的时候又都是对的,难道是python自动保存了什么数据没清空吗?还是什么原因,实在想不明白,请大家帮忙解答,万分感谢!
def bandpass(data, f1, f2, step, sfreq):
wn1 = 2*f1/sfreq
wn2 = 2*f2/sfreq
redata = data
#带通滤波
for subject in redata:
for session in redata[subject]:
for channel in redata[subject][session]:
for event in range(len(redata[subject][session][channel])):
#带通滤波
[b, a] = signal.butter(step, [wn1, wn2], 'bandpass') #8
data_bandpass = signal.filtfilt(b, a, redata[subject][session][channel][event])
redata[subject][session][channel][event] = data_bandpass
return redata
if __name__ == "__main__":
data = np.load('data.npy', allow_pickle=True).item()
sfreq = 250
data_bandpass47 = bandpass(data=data, f1=4, f2=7, step=4, sfreq=sfreq)
data_bandpass813 = bandpass(data=data, f1=8, f2=13, step=8, sfreq=sfreq)
data_bandpass1332 = bandpass(data=data, f1=13, f2=32, step=12, sfreq=sfreq)