def test_check_filter_properties(): filter_coefs = design_fir_filter(FS, 'bandpass', (8, 12)) # Check valid / passing filter passes = check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12)) assert passes is True # Check failing filter - insufficient attenuation with warnings.catch_warnings(record=True) as warn: filter_coefs = design_fir_filter(FS, 'bandstop', (8, 12)) passes = check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12)) assert passes is False assert len(warn) == 1 assert "filter attenuation" in str(warn[-1].message) # Check failing filter - transition bandwidth with warnings.catch_warnings(record=True) as warn: filter_coefs = design_fir_filter(FS, 'bandpass', (20, 21)) passes = check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12)) assert passes is False assert len(warn) == 1 assert "Transition bandwidth" in str(warn[-1].message) # Check failing filter - insufficient attenuation on part of stopband with warnings.catch_warnings(record=True) as w: filter_coefs = design_fir_filter(FS, 'bandpass', (5, 40), n_cycles=1) check_filter_properties(filter_coefs, 1, FS, 'bandpass', (5, 40)) assert len(w) == 1 assert "stopband" in str(w[-1].message)
def test_compute_frequency_response(): filter_coefs = design_fir_filter(FS, 'bandpass', (8, 12)) f_db, db = compute_frequency_response(filter_coefs, 1, FS) with raises(ValueError): f_db, db = compute_frequency_response(filter_coefs, None, FS)
def test_plot_impulse_response(): coefs = design_fir_filter(FS, 'bandpass', (8, 12), 3) plot_impulse_response(FS, coefs, save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_impulse_response.png')
def test_plot_impulse_response(): fs = 1000 coefs = design_fir_filter(2000, fs, 'bandpass', (8, 12), 3) plot_impulse_response(fs, coefs) assert True
def test_plot_frequency_response(): coefs = design_fir_filter(2000, 1000, 'bandpass', (8, 12), 3) f_db, db = compute_frequency_response(coefs, a_vals=1, fs=1000) plot_frequency_response(f_db, db) assert True
def test_plot_frequency_response(): coefs = design_fir_filter(FS, 'bandpass', (8, 12), 3) f_db, db = compute_frequency_response(coefs, a_vals=1, fs=FS) plot_frequency_response(f_db, db, save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_frequency_response.png')
def test_plot_filter_properties(): fs = 1000 coefs = design_fir_filter(2000, fs, 'bandpass', (8, 12), 3) f_db, db = compute_frequency_response(coefs, a_vals=1, fs=1000) plot_filter_properties(f_db, db, fs, coefs) assert True
def test_compute_transition_band(): filter_coefs = design_fir_filter(FS, 'bandpass', (8, 12)) f_db, db = compute_frequency_response(filter_coefs, 1, FS) trans_band = compute_transition_band(f_db, db)
def test_compute_frequency_response(): filter_coefs = design_fir_filter(FS, 'bandpass', (8, 12)) f_db, db = compute_frequency_response(filter_coefs, 1, FS)
def test_check_filter_properties(): filter_coefs = design_fir_filter(1000, 500, 'bandpass', (8, 12)) check_filter_properties(filter_coefs, 1, 500, 'bandpass', (8, 12)) assert True
def test_plot_impulse_response(): coefs = design_fir_filter(FS, 'bandpass', (8, 12), 3) plot_impulse_response(FS, coefs)
def test_plot_frequency_response(): coefs = design_fir_filter(FS, 'bandpass', (8, 12), 3) f_db, db = compute_frequency_response(coefs, a_vals=1, fs=FS) plot_frequency_response(f_db, db)
def test_compute_transition_band(): filter_coefs = design_fir_filter(1000, 500, 'bandpass', (8, 12)) f_db, db = compute_frequency_response(filter_coefs, 1, 500) trans_band = compute_transition_band(f_db, db) assert True
# # We also need to specify the filter length, which can be defined either in seconds, or as a # number of cycles (defined as the low cutoff frequency). The default filter length is 3 cycles. # You may need to update this value to customize the filter length, as this impacts the # frequency response. # ################################################################################################### # Define filter settings pass_type = 'bandpass' f_range = (8, 13) n_cycles = 3 # Design the filter coefficients for a specified filter filter_coefs = design_fir_filter(fs, pass_type, f_range, n_cycles=n_cycles) ################################################################################################### # # Now that we have our filter coefficients, we can evaluate our filter. # # Next, we can calculate the frequency response, :math:`b_k`, for our alpha bandpass filter. # ################################################################################################### # Compute the frequency response of the filter f_db, db = compute_frequency_response(filter_coefs, 1, fs) # Plot the filter properties plot_filter_properties(f_db, db, fs, filter_coefs)