def __init__(self, parent=None): super().__init__(parent) self.ui = Ui_DialogFilterBandwidth() self.ui.setupUi(self) bw_type = constants.SETTINGS.value("bandpass_filter_bw_type", "Medium", str) custom_bw = constants.SETTINGS.value("bandpass_filter_custom_bw", 0.1, float) for item in dir(self.ui): item = getattr(self.ui, item) if isinstance(item, QLabel): name = item.objectName().replace("label", "") key = next((key for key in Filter.BANDWIDTHS.keys() if name.startswith(key.replace(" ", ""))), None) if key is not None and name.endswith("Bandwidth"): item.setText("{0:n}".format(Filter.BANDWIDTHS[key])) elif key is not None and name.endswith("KernelLength"): item.setText( str( Filter.get_filter_length_from_bandwidth( Filter.BANDWIDTHS[key]))) elif isinstance(item, QRadioButton): item.setChecked( bw_type.replace(" ", "_") == item.objectName().replace( "radioButton", "")) self.ui.doubleSpinBoxCustomBandwidth.setValue(custom_bw) self.ui.spinBoxCustomKernelLength.setValue( Filter.get_filter_length_from_bandwidth(custom_bw)) self.create_connects()
def __init__(self, parent=None): super().__init__(parent) self.ui = Ui_DialogFilterBandwidth() self.ui.setupUi(self) self.setWindowFlags(Qt.Window) bw_type = constants.SETTINGS.value("bandpass_filter_bw_type", "Medium", str) custom_bw = constants.SETTINGS.value("bandpass_filter_custom_bw", 0.1, float) for item in dir(self.ui): item = getattr(self.ui, item) if isinstance(item, QLabel): name = item.objectName().replace("label", "") key = next((key for key in Filter.BANDWIDTHS.keys() if name.startswith(key.replace(" ", ""))), None) if key is not None and name.endswith("Bandwidth"): item.setText("{0:n}".format(Filter.BANDWIDTHS[key])) elif key is not None and name.endswith("KernelLength"): item.setText(str(Filter.get_filter_length_from_bandwidth(Filter.BANDWIDTHS[key]))) elif isinstance(item, QRadioButton): item.setChecked(bw_type.replace(" ", "_") == item.objectName().replace("radioButton", "")) self.ui.doubleSpinBoxCustomBandwidth.setValue(custom_bw) self.ui.spinBoxCustomKernelLength.setValue(Filter.get_filter_length_from_bandwidth(custom_bw)) self.create_connects()
def test_bandpass_h(self): f_low = -0.4 f_high = -0.3 bw = 0.01 f_shift = (f_low + f_high) / 2 f_c = (f_high - f_low) / 2 N = Filter.get_filter_length_from_bandwidth(bw) h = Filter.design_windowed_sinc_lpf(f_c, bw=bw) * np.exp( np.complex(0, 1) * np.pi * 2 * f_shift * np.arange(0, N, dtype=complex)) #h = Filter.design_windowed_sinc_bandpass(f_low=f_low, f_high=f_high, bw=bw) #h = Filter.design_windowed_sinc_lpf(0.42, bw=0.08) impulse = np.exp(1j * np.linspace(0, 1, 50)) plt.subplot("221") plt.title("f_low={} f_high={} bw={}".format(f_low, f_high, bw)) plt.plot(np.fft.fftfreq(1024), np.fft.fft(h, 1024)) plt.subplot("222") plt.plot(h) plt.show()
def test_bandpass_h(self): f_low = -0.4 f_high = -0.3 bw = 0.01 f_shift = (f_low + f_high) / 2 f_c = (f_high - f_low) / 2 N = Filter.get_filter_length_from_bandwidth(bw) h = Filter.design_windowed_sinc_lpf(f_c, bw=bw) * np.exp(np.complex(0,1) * np.pi * 2 * f_shift * np.arange(0, N, dtype=complex)) #h = Filter.design_windowed_sinc_bandpass(f_low=f_low, f_high=f_high, bw=bw) #h = Filter.design_windowed_sinc_lpf(0.42, bw=0.08) impulse = np.exp(1j * np.linspace(0, 1, 50)) plt.subplot("221") plt.title("f_low={} f_high={} bw={}".format(f_low, f_high, bw)) plt.plot(np.fft.fftfreq(1024), np.fft.fft(h, 1024)) plt.subplot("222") plt.plot(h) plt.show()
def test_change_custom_bw(self): bw = 0.3 N = Filter.get_filter_length_from_bandwidth(bw) self.dialog.ui.doubleSpinBoxCustomBandwidth.setValue(bw) self.assertEqual(N, self.dialog.ui.spinBoxCustomKernelLength.value()) N = 401 bw = Filter.get_bandwidth_from_filter_length(N) self.dialog.ui.spinBoxCustomKernelLength.setValue(N) self.assertAlmostEqual(bw, self.dialog.ui.doubleSpinBoxCustomBandwidth.value(), places=self.dialog.ui.doubleSpinBoxCustomBandwidth.decimals())
def on_spin_box_custom_bandwidth_value_changed(self, bw: float): self.ui.spinBoxCustomKernelLength.blockSignals(True) self.ui.spinBoxCustomKernelLength.setValue(Filter.get_filter_length_from_bandwidth(bw)) self.ui.spinBoxCustomKernelLength.blockSignals(False)
def on_spin_box_custom_bandwidth_value_changed(self, bw: float): self.ui.spinBoxCustomKernelLength.blockSignals(True) self.ui.spinBoxCustomKernelLength.setValue(Filter.get_filter_length_from_bandwidth(bw)) self.ui.spinBoxCustomKernelLength.blockSignals(False)