def test_first_order_bounce_correction(self): hw_corr = ZI_kf.first_order_bounce_corr(self.distorted_waveform, self.bounce_delay, self.bounce_amp, self.sampling_rate) ainv1 = ZI_kf.first_order_bounce_kern(self.bounce_delay, -self.bounce_amp, self.sampling_rate) first_order_corr = signal.lfilter(ainv1, 1, self.distorted_waveform) np.testing.assert_almost_equal(hw_corr, first_order_corr, 4)
def test_ideal_bounce_correction(self): # Construct impulse response impulse = np.zeros(len(self.time)) zero_ind = np.argmin(np.abs(self.time)) impulse[zero_ind] = 1.0 a = ZI_kf.first_order_bounce_kern(self.bounce_delay, self.bounce_amp, self.sampling_rate) impulse_response = signal.lfilter([1.0], a, impulse) b_inv = ZI_kf.ideal_inverted_fir_kernel(impulse_response, zero_ind) ideal_corr = signal.lfilter(b_inv, 1.0, self.distorted_waveform) np.testing.assert_almost_equal(ideal_corr, self.ideal_waveform, 6)
def test_first_order_bounce_correction(self): hw_corr = ZI_kf.first_order_bounce_corr(self.distorted_waveform, self.bounce_delay, self.bounce_amp, self.sampling_rate) b = ZI_kf.first_order_bounce_kern( self.bounce_delay, ZI_kf.coef_round(self.bounce_amp, force_bshift=0), self.sampling_rate) first_order_corr = signal.lfilter(b, 1.0, self.distorted_waveform) np.testing.assert_almost_equal(hw_corr, first_order_corr, 6)
zero_ind = np.argmin(np.abs(time)) impulse[zero_ind] = 1.0 delay_ind = np.argmin(np.abs(time-delay)) impulse_response = np.copy(impulse) impulse_response[delay_ind] = amplitude # Derive step response step = np.zeros(len(time)) step[time >= 0.0] = 1.0 step_response = signal.lfilter(impulse_response[zero_ind:], 1.0, step) # Compute ideal inverted filter kernel a = ZI_kern.ideal_inverted_fir_kernel(impulse_response, zero_ind) a1 = ZI_kern.first_order_bounce_kern(delay, -amplitude, fs) # Apply ideal inverted filter to impulse response and step response impulse_response_corr = signal.lfilter(a, 1.0, impulse_response) step_response_corr = signal.lfilter(a, 1.0, step_response) # Apply first-order inverted filter to impulse response and step response impulse_response_corr1 = signal.lfilter(a1, 1.0, impulse_response) step_response_corr1 = signal.lfilter(a1, 1.0, step_response) # Apply hardware-friendly filter to impulse response and step response impulse_response_corr_hw = ZI_kern.multipath_first_order_bounce_correction(impulse_response, round(delay*fs), amplitude) step_response_corr_hw = ZI_kern.multipath_first_order_bounce_correction(step_response, round(delay*fs), amplitude) # Plot impulse response comparison
def compute_distorted_waveform(self): a = ZI_kf.first_order_bounce_kern(self.bounce_delay, self.bounce_amp, self.sampling_rate) self.distorted_waveform = signal.lfilter([1.0], a, self.ideal_waveform)
mpl.rcParams['font.size'] = 12 mpl.rcParams['legend.fontsize'] = 12 mpl.rcParams['figure.titlesize'] = 'medium' # Settings fs = 2.4e9 time_start = -100e-9 time_start = np.around(time_start * fs) / fs time_end = 100e-9 time = np.arange(time_start, time_end, 1 / fs) bounce_delay = 10.1e-9 bounce_amp = 0.1 # Get filter kernel for bounce a = ZI_kf.first_order_bounce_kern(bounce_delay, bounce_amp, fs) # Construct impulse impulse = np.zeros(len(time)) zero_ind = np.argmin(np.abs(time)) impulse[zero_ind] = 1.0 # Construct step step = np.zeros(len(time)) step[time >= 0.0] = 1.0 # Apply forward filter to impulse and step response impulse_response = signal.lfilter([1.0], a, impulse) step_response = signal.lfilter([1.0], a, step) # Compute ideal inverted filter kernel
def test_ideal_bounce_correction(self): a = ZI_kf.first_order_bounce_kern(self.bounce_delay, self.bounce_amp, self.sampling_rate) ainv = ZI_kf.ideal_inverted_fir_kernel(a, zero_padding=100) ideal_corr = signal.lfilter(ainv, 1, self.distorted_waveform) np.testing.assert_almost_equal(ideal_corr, self.ideal_waveform, 4)