def design_sosmat_low_pass_high_pass_bounds(order, band_edges, sample_rate): """Returns matrix containing sos coeffs of low and highpass. The cutoff frequencies are placed at the first and last band edge. .. note:: This funtion is not used anymore. Parameters ---------- order : int Order of the band pass filters. band_edges : ndarray Band edge frequencies for the low an highpass. sample_rate : scalar Sample rate. Returns ------- sosdict : ndarray Second order section coefficients, the first column contains the low pass coefs and the second column contains the highpass coeffs. """ sosmat = zeros((0.5 * order * 6, 2)) band_edges_normalized = to_normalized_frequencies(band_edges, sample_rate) sosmat[:, 0] = butter_sos('lowpass', order, band_edges_normalized[0]).flatten() sosmat[:, 1] = butter_sos('highpass', order, band_edges_normalized[-1]).flatten() return sosmat
def design_sosmat_low_pass_high_pass_bounds(order, band_edges, sample_rate): """Returns matrix containing sos coeffs of low and highpass. The cutoff frequencies are placed at the first and last band edge. .. note:: This funtion is not used anymore. Parameters ---------- order : int Order of the band pass filters. band_edges : ndarray Band edge frequencies for the low an highpass. sample_rate : scalar Sample rate. Returns ------- sosdict : ndarray Second order section coefficients, the first column contains the low pass coefs and the second column contains the highpass coeffs. """ sosmat = zeros((0.5*order*6, 2)) band_edges_normalized = to_normalized_frequencies(band_edges, sample_rate) sosmat[:, 0] = butter_sos('lowpass', order, band_edges_normalized[0]).flatten() sosmat[:, 1] = butter_sos('highpass', order, band_edges_normalized[-1]).flatten() return sosmat
def test_bandstop(self): sosmat = bw.butter_sos('bandstop', 2, self.v1, self.v2) self.assertTrue(np.all(np.isfinite(sosmat))) x, y, F, Y = sf.freqz(sosmat, sample_rate=self.sample_rate, plot=False) mask = np.logical_and(F >= self.v1 * self.sample_rate, F <= self.v2 * self.sample_rate) self.assertTrue(np.all(np.abs(Y[mask]) <= 1.0 / np.sqrt(2)))
def test_highpass(self): sosmat = bw.butter_sos('highpass', 2, self.v1) self.assertTrue(np.all(np.isfinite(sosmat))) x, y, F, Y = sf.freqz( sosmat, sample_rate=self.sample_rate, plot=False) mask = np.logical_and(F <= self.v1*self.sample_rate, F >=0) self.assertTrue(np.all(np.abs(Y[mask]) <= 1.0/np.sqrt(2)))
def test_lowpass(self): sosmat = bw.butter_sos('lowpass', 2, self.v1) self.assertTrue(np.all(np.isfinite(sosmat))) x, y, F, Y = sf.freqz( sosmat, sample_rate=self.sample_rate, plot=False) mask = F >= self.v1*self.sample_rate self.assertTrue(np.all(np.abs(Y[mask]) <= 1.0/np.sqrt(2)))
def test_bandstop(self): sosmat = bw.butter_sos('bandstop', 2, self.v1, self.v2) self.assertTrue(np.all(np.isfinite(sosmat))) x, y, F, Y = sf.freqz( sosmat, sample_rate=self.sample_rate, plot=False) mask = np.logical_and(F >= self.v1*self.sample_rate, F <= self.v2*self.sample_rate) self.assertTrue(np.all(np.abs(Y[mask]) <= 1.0/np.sqrt(2)))
def design_sosmat_band_passes(order, band_edges, sample_rate, edge_correction_percent=0.0): """Return matrix containig sos coeffs of bandpasses. Parameters ---------- order : int Order of the band pass filters. band_edges : ndarray Band edge frequencies for the bandpasses. sample_rate : scalar Sample frequency. edge_correction_percent : scalar Percentage for the correction of the bandedges. Float between -100 % and 100 %. It can be helpfull dependent on the used filter order. p > 0 widens the band passes. Returns ------- sosmat : ndarray Second order section coefficients. Each column is one band pass cascade of coefficients. """ num_coeffs_biquad_bandpass = 6 num_coeffs_cascade = order * num_coeffs_biquad_bandpass num_bands = len(band_edges) - 1 sosmat = zeros((num_coeffs_cascade, num_bands)) band_edges_normalized = to_normalized_frequencies(band_edges, sample_rate) p_lower = (1 - edge_correction_percent*1e-2) p_upper = (1 + edge_correction_percent*1e-2) for i, (lower_freq, upper_freq) in enumerate(zip( band_edges_normalized[:-1], band_edges_normalized[1:])): sos = butter_sos('bandpass', order, p_lower*lower_freq, p_upper*upper_freq) sosmat[:, i] = sos.flatten() return sosmat
def design_sosmat_band_passes(order, band_edges, sample_rate, edge_correction_percent=0.0): """Return matrix containig sos coeffs of bandpasses. Parameters ---------- order : int Order of the band pass filters. band_edges : ndarray Band edge frequencies for the bandpasses. sample_rate : scalar Sample frequency. edge_correction_percent : scalar Percentage for the correction of the bandedges. Float between -100 % and 100 %. It can be helpfull dependent on the used filter order. p > 0 widens the band passes. Returns ------- sosmat : ndarray Second order section coefficients. Each column is one band pass cascade of coefficients. """ num_coeffs_biquad_bandpass = 6 num_coeffs_cascade = order * num_coeffs_biquad_bandpass num_bands = len(band_edges) - 1 sosmat = zeros((num_coeffs_cascade, num_bands)) band_edges_normalized = to_normalized_frequencies(band_edges, sample_rate) p_lower = (1 - edge_correction_percent * 1e-2) p_upper = (1 + edge_correction_percent * 1e-2) for i, (lower_freq, upper_freq) in enumerate( zip(band_edges_normalized[:-1], band_edges_normalized[1:])): sos = butter_sos('bandpass', order, p_lower * lower_freq, p_upper * upper_freq) sosmat[:, i] = sos.flatten() return sosmat
def test_highpass(self): sosmat = bw.butter_sos('highpass', 2, self.v1) self.assertTrue(np.all(np.isfinite(sosmat))) x, y, F, Y = sf.freqz(sosmat, sample_rate=self.sample_rate, plot=False) mask = np.logical_and(F <= self.v1 * self.sample_rate, F >= 0) self.assertTrue(np.all(np.abs(Y[mask]) <= 1.0 / np.sqrt(2)))
def test_lowpass(self): sosmat = bw.butter_sos('lowpass', 2, self.v1) self.assertTrue(np.all(np.isfinite(sosmat))) x, y, F, Y = sf.freqz(sosmat, sample_rate=self.sample_rate, plot=False) mask = F >= self.v1 * self.sample_rate self.assertTrue(np.all(np.abs(Y[mask]) <= 1.0 / np.sqrt(2)))