python - Unable to extend scipy.signal.filt.filt example to a high pass filter -
i trying implement high pass filter in python using scipy.signal.filt.filt. however, attempts modify example given in documentation (http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.filtfilt.html) have been unsuccessful.
defining signal:
t = np.linspace(0.0, 1.0, 2001) xlow = np.sin(10.0 * t) xhigh = 10.0*np.sin(50. * t) x = xlow + xhigh
defining filter cut-off frequency of 20 rad/s (to remove low frequency component of x) , plotting frequency response:
b, = signal.iirfilter(17, 20, btype='highpass', analog=true, ftype='butter') w, h = signal.freqs(b, a) plt.plot(w, 20.0 * np.log10(abs(h))) plt.xscale('log') plt.title('butterworth filter frequency response') plt.xlabel('frequency [radians / second]') plt.ylabel('amplitude [db]') plt.margins(0, 0.1) plt.grid(which='both', axis='both') plt.show() plt.close()
the plot shows cut-off around 20 rad/s expected.
applying filter , plotting filtered signal against original:
y = signal.filtfilt(b, a, x, padtype='even', padlen=150) fig = plt.figure(figsize = [10,10]) ax = fig.add_subplot(1,1,1) ax.plot(t,x, 'b-', label='original') ax.plot(t,y.real, 'rs', label='filtered') ax.legend() plt.xlabel("time (s)") plt.ylabel("signal") plt.show() plt.close()
no error messages returned, filtered signal, y, nan+nanj values.
can see i'm going wrong?
thanks
Comments
Post a Comment