def notch_filter(data, lowcut, highcut, fs, order=5, rs=10): # Chebyshev notch filter centered on 50Hz nyquist = fs / 2.0 b, a = filter_design.iirfilter(order, (lowcut/nyquist, highcut/nyquist), rs=rs, ftype='cheby2') # filter the signal arrFiltered = filtfilt(b, a, data) return arrFiltered
Wp = cutoff_hz/nyq_rate # Cutoff frequency Ws = (cutoff_hz+1.5)/nyq_rate # Stop frequency Rp = 1 # Ripple in the passband maximum loss (gpass) As = 42 # Min Attenuation in the stoppand (gstop) Filters = {'ellip' : (), 'cheby2' : (), 'butter' : (), 'cheby1' : (), 'bessel' : ()} # The ellip and cheby2 filter design Filters['ellip'] = fd.iirdesign(Wp, Ws, Rp, As, ftype='ellip') Filters['cheby2'] = fd.iirdesign(Wp, Ws, Rp, As, ftype='cheby2') Filters['butter'] = fd.iirdesign(Wp, Ws, Rp, As, ftype='butter') Filters['cheby1'] = fd.iirdesign(Wp, Ws, Rp, As, ftype='cheby1') # The bessel max order of 8 for this cutoff, can't use # iirdesign have to use iirfilter. Filters['bessel'] = fd.iirfilter(8, Wp, btype='lowpass', ftype='bessel') ## Pass the signal though the filter velocity = reference_velocity.getAxis(0) velocityfilter = {'ellip' : (), 'cheby2' : (), 'butter' : (), 'cheby1' : (), 'bessel' : ()} velocityfilter['ellip'] = sig.lfilter(Filters['ellip'][0], Filters['ellip'][1], velocity) velocityfilter['cheby2'] = sig.lfilter(Filters['cheby2'][0], Filters['cheby2'][1], velocity) velocityfilter['butter'] = sig.lfilter(Filters['butter'][0], Filters['butter'][1], velocity) velocityfilter['cheby1'] = sig.lfilter(Filters['cheby1'][0], Filters['cheby1'][1], velocity) velocityfilter['bessel'] = sig.lfilter(Filters['bessel'][0], Filters['bessel'][1], velocity) ################# ### GRAPHICS ### ################# plt.figure(4)
def filter_50Hz(sample): # Chebyshev notch filter centered on 50Hz nyquist = FREQ / 2. b, a = filter_design.iirfilter(3, (49. / nyquist, 51. / nyquist), rs=10, ftype='cheby2') sample_50Hz = filtfilt(b, a, sample) return(sample - sample_50Hz)
print(name) dset = f['signal_1/sig'] print(dset) print(dset.shape) # print dset.type # frequence d'echantillonage en Hz freq = 250 length_acquisition = dset.shape[0] / (freq*60) # in minutes print("the acquisition is ", length_acquisition, " minutes long") plt.plot(dset) plt.ylabel('Louis Gauche Raw signal') plt.show() # Chebyshev notch filter centered on 50Hz nyquist = freq / 2. b, a = filter_design.iirfilter(3, (49. / nyquist, 51. / nyquist), rs=10, ftype='cheby2') # filter the signal print("filtering ...") x50 = filtfilt(b, a, dset) xfilt = dset - x50 plt.plot(xfilt, label='50Hz bandpass-filtered') plt.show()
#print (str(audio_data[m])+" "+str(audio_output[m])+" "+str(absolute[m])+"\n") if order==3: for m in range(0, length_audio_data): audio_output[m]=audio_data[m-3]-3*a_cong*audio_data[m-2]+3*(a_cong**2)*audio_data[m-1]-(a_cong**3)*audio_data[m]+(a**3)*audio_output[m-3]-3*(a**2)*audio_output[m-2]+3*a*audio_output[m-1] absolute[m]=np.absolute(audio_output[m]) absolute[m]=absolute[m].astype(int) audio_input[m]=audio_data[m] ------------------------------------------------------------------------ if order==4: for m in range(0, length_audio_data): audio_output[m]=audio_data[m-4]-4*(a_cong)*audio_data[m-3]+6*(a_cong**2)*audio_data[m-2]-4*(a_cong**3)*audio_data[m-1]+(a_cong**4)*audio_data[m]-(a**4)*audio_output[m-4]+4*(a**3)*audio_output[m-3]-6*(a**2)*audio_output[m-2]+4*a*audio_output[m-1] absolute[m]=np.absolute(audio_output[m]) audio_input[m]=audio_data[m] if order==5: for m in range(0, length_audio_data): audio_output[m]=audio_data[m-5]-5*(a_cong)*audio_data[m-4]+10*(a_cong**2)*audio_data[m-3]-10*(a_cong**3)*audio_data[m-2]+5*(a_cong**4)*audio_data[m-1]-(a_cong**5)*audio_data[m]+(a**5)*audio_output[m-5]-5*(a**4)*audio_output[m-4]+10*(a**3)*audio_output[m-3]-10*(a**2)*audio_output[m-2]+5*a*audio_output[m-1] absolute[m]=np.absolute(audio_output[m]) audio_input[m]=audio_data[m] """ n=17 wp=0.27 ws=0.7 a,b=fd.iirfilter(n,[0.27,0.67],btype='lowpass', ftype='butter') print(str(a))