1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| from scipy import signal import numpy as np y = np.array([ 1.74082189, -0.12322827, 1.18896494, 0.79653332, 0.60031752, 0.95595867, -0.01285688, -0.51565989, 3.23696743, 1.47102516, -0.18454571, 1.98609165, 1.09085703, 0.84558727, 0.56352705, 0.12204148, -0.38076152, -1.10430731, 0.09751451, 1.09085703, -0.14775525, 1.3238633, 1.07859355, -1.2146787, 0.13430497, 0.29373032, -1.96275147, -0.93261848, -0.58924082, 0.95595867, 0.67389844, -0.98167243, -0.85903755, -0.23359967, -0.35623455, 0.24467636, -0.28265362, -1.26373265, -0.83451058, -0.88356453, 0.52673659, -0.22133618, -0.74866616, 0.18335892, -0.72413918, -0.22133618, -0.24586315, -0.87130104, 0.71068891, -1.37410405, -1.90143403, 0.50220961, 1.75308538, -0.08643781, -0.13549176, 0.04846056, -1.50900241, -0.35623455, 0.15883195, -1.25146917, -0.44207896, -1.423158 ])
b1, a1 = signal.butter(3, 2/3, 'highpass') high_series = signal.filtfilt(b1, a1, y)
b2, a2 = signal.butter(3, [2/10,2/3], 'bandpass') band_series = signal.filtfilt(b2, a2, y)
b3, a3 = signal.butter(3, 2/10, 'lowpass') low_series = signal.filtfilt(b3, a3, y)
fig = plt.figure(figsize=(10, 4)) ax1 = fig.add_subplot(1,3,1) ax1.plot(np.arange(0,62,1),y,'k',label='y') ax1.plot(np.arange(0,62,1),high_series,'r',label='highpass') ax1.legend() ax2 = fig.add_subplot(1,3,2) ax2.plot(np.arange(0,62,1),y,'k',label='y') ax2.plot(np.arange(0,62,1),band_series,'r',label='bandpass') ax2.legend() ax3 = fig.add_subplot(1,3,3) ax3.plot(np.arange(0,62,1),y,'k',label='y') ax3.plot(np.arange(0,62,1),low_series,'r',label='lowpass') ax3.legend() plt.show()
|