def low_pass_filter(self, filter_freq=None): """ Low pass filter the data """ from gwpy.signal.filter_design import lowpass from gwpy.timeseries import TimeSeries if filter_freq is None: logger.debug( "Setting low pass filter_freq using given maximum frequency") filter_freq = self.maximum_frequency if 2 * filter_freq >= self.sampling_frequency: logger.info( "Low pass filter frequency of {}Hz requested, this is equal" " or greater than the Nyquist frequency so no filter applied". format(filter_freq)) return logger.debug( "Applying low pass filter with filter frequency {}".format( filter_freq)) bp = lowpass(filter_freq, self.sampling_frequency) strain = TimeSeries(self.time_domain_strain, sample_rate=self.sampling_frequency) strain = strain.filter(bp, filtfilt=True) self._time_domain_strain = strain.value
def test_lowpass(self): iir = filter_design.lowpass(100, 1024) utils.assert_zpk_equal(iir, LOWPASS_IIR_100HZ) fir = filter_design.lowpass(100, 1024, type='fir') utils.assert_allclose(fir, LOWPASS_FIR_100HZ)
def main(start, end, chname): data = TimeSeries.read(dumped_gwf_fmt.format(start=start, end=end, chname=channel), channel, verbose=True, nproc=8) # Filtering from gwpy.signal import filter_design from gwpy.plot import BodePlot import numpy bp_high = filter_design.highpass( 0.3, data.sample_rate, analog=True, ftype='butter', gpass=2, gstop=30 #,fstop() ) bp_mid = filter_design.bandpass( 0.05, 0.3, data.sample_rate, analog=True, ftype='butter', gpass=2, gstop=30 #,fstop=(0.01,0.5) ) bp_low = filter_design.lowpass( 0.05, data.sample_rate, analog=True, ftype='butter', gpass=2, gstop=30 #, fstop=2 ) filters = [bp_high, bp_mid, bp_low] plot = BodePlot(*filters, analog=True, frequencies=numpy.logspace(-3, 1, 1e5), dB=False, unwrap=False, title='filter') axes = plot.get_axes() axes[0].set_yscale('log') axes[0].set_ylim(1e-4, 2e0) axes[-1].set_xlim(1e-2, 1e0) axes[-1].set_ylim(-180, 180) plot.savefig('Bodeplot_BandPass.png') plot.close() data_high = data.filter(bp_high, filtfilt=True) data_high = data_high.crop(*data_high.span.contract(1)) data_mid = data.filter(bp_mid, filtfilt=True) data_mid = data_mid.crop(*data_mid.span.contract(1)) data_low = data.filter(bp_low, filtfilt=True) data_low = data_low.crop(*data_low.span.contract(1)) # Plot TimeSeries title = channel[3:].replace('_', ' ') labels = [ 'No filt', 'High (300mHz-)', 'Mid (50mHz-300mHz)', 'Low (-50mHz)' ] if data.unit == ' ': yaxis_label = 'Count' else: yaxis_label = data.unit from gwpy.plot import Plot data_set = [data, data_high, data_mid, data_low] plot = Plot(*data_set, separate=True, sharex=True, sharey=True, color='gwpy:ligo-livingston', figsize=[10, 10]) axes = plot.get_axes() for i, ax in enumerate(axes): ax.legend([labels[i]], loc='upper left') plot.text(0.04, 0.5, yaxis_label, va='center', rotation='vertical', fontsize=16) #plot.text(0.5, 0.93, title, va='center',ha='center',rotation='horizontal',fontsize=16) axes[0].set_title(title, fontsize=16) axes[-1].set_xscale('Hours', epoch=start) plot.savefig(timeseriesplot_fname_fmt.format(channel=channel)) plot.close()
# To create a low-pass filter at 1000 Hz for 4096 Hz-sampled data: from gwpy.signal.filter_design import lowpass lp = lowpass(1000, 4096) # To view the filter, you can use the `~gwpy.plotter.BodePlot`: from gwpy.plotter import BodePlot plot = BodePlot(lp, sample_rate=4096) plot.show()
def main(channel,start,end): data = TimeSeries.read( dumped_gwf_fmt.format(start=start,end=end,chname=channel), channel, verbose=True ,nproc=8) # Filter zpk_bp_high = filter_design.highpass(0.3, data.sample_rate, ftype='butter',analog=False, gpass=2,gstop=40,fstop=0.03 ) zpk_bp_mid = filter_design.bandpass(0.03, 0.3, data.sample_rate, ftype='butter',analog=False, gpass=2, gstop=40,fstop=(0.003,3) ) zpk_bp_low = filter_design.lowpass(0.03, data.sample_rate, ftype='butter',analog=False, gpass=2, gstop=40, fstop=0.3 ) filters = [zpk_bp_high, zpk_bp_mid, zpk_bp_low] # Plot Bodeplot plot = BodePlot(*filters, frequencies=numpy.logspace(-4,1,1e5), dB=True,sample_rate=data.sample_rate, unwrap=False,analog=False, title='filter') axes = plot.get_axes() labels = ['High (300mHz-)','Mid (50mHz-300mHz)','Low (-50mHz)'] for i,ax in enumerate(axes): ax.legend(labels,loc='lower left') #axes[0].set_yscale('log') #axes[0].set_ylim(1e-3,2e0) axes[0].set_ylim(-40,2) axes[-1].set_xlim(5e-3,3e0) axes[-1].set_ylim(-200,200) plot.savefig('Bodeplot_BandPass.png') plot.close() # Filtering data_high = data.filter(zpk_bp_high, filtfilt=True,analog=False) data_mid = data.filter(zpk_bp_mid, filtfilt=True,analog=False) data_low = data.filter(zpk_bp_low, filtfilt=True,analog=False) # data_high = data_high.crop(*data_high.span.contract(1)) data_mid = data_mid.crop(*data_mid.span.contract(1)) data_low = data_low.crop(*data_low.span.contract(1)) # Plot TimeSeries from gwpy.plot import Plot data_set = [data,data_high, data_mid, data_low] plot = Plot(*data_set, separate=True, sharex=True, sharey=True, color='gwpy:ligo-livingston', figsize=[10,10]) # Add text, and save figure title = channel[3:].replace('_',' ') labels = ['No filt', 'High (300mHz-)', 'Mid (50mHz-300mHz)', 'Low (-50mHz)'] if data.unit == ' ': yaxis_label = 'Count' else: yaxis_label = data.unit axes = plot.get_axes() for i,ax in enumerate(axes): ax.legend([labels[i]],loc='upper left') plot.text(0.04, 0.5, yaxis_label, va='center', rotation='vertical',fontsize=18) axes[0].set_title(title,fontsize=16) axes[-1].set_xscale('Hours', epoch=start) plot.savefig(timeseriesplot_fname_fmt.format(channel=channel)) plot.close()