From 28ff8cdacf53e0103810e39e83be21e6780936b9 Mon Sep 17 00:00:00 2001 From: jopohl Date: Tue, 19 Apr 2016 17:49:34 +0200 Subject: [PATCH] remove unecassary filters --- .../controller/ModulatorDialogController.py | 20 ++++-- src/urh/signalprocessing/Modulator.py | 64 ------------------- 2 files changed, 13 insertions(+), 71 deletions(-) diff --git a/src/urh/controller/ModulatorDialogController.py b/src/urh/controller/ModulatorDialogController.py index b87dd9e5..7ea185b5 100644 --- a/src/urh/controller/ModulatorDialogController.py +++ b/src/urh/controller/ModulatorDialogController.py @@ -171,6 +171,11 @@ class ModulatorDialogController(QDialog): else: self.ui.btnRestoreBits.setEnabled(True) + def __cur_selected_mod_type(self): + s = self.ui.comboBoxModulationType.currentText() + return s[s.rindex("(")+1:s.rindex(")")] + + @pyqtSlot() def on_sample_rate_changed(self): if int(self.ui.spinBoxSampleRate.value()) > 0: @@ -190,13 +195,13 @@ class ModulatorDialogController(QDialog): @pyqtSlot() def on_modulation_type_changed(self): - if self.current_modulator.modulation_type == self.ui.comboBoxModulationType.currentIndex(): + if self.current_modulator.modulation_type_str == self.__cur_selected_mod_type(): write_standard_parameters = False else: - self.current_modulator.modulation_type = self.ui.comboBoxModulationType.currentIndex() + self.current_modulator.modulation_type_str = self.__cur_selected_mod_type() write_standard_parameters = True - if self.ui.comboBoxModulationType.currentIndex() == 0: + if self.__cur_selected_mod_type() == "ASK": self.ui.lParameterfor0.setText(self.tr("Amplitude for 0:")) self.ui.lParameterfor1.setText(self.tr("Amplitude for 1:")) self.ui.spinBoxParameter0.auto_suffix = False @@ -216,7 +221,7 @@ class ModulatorDialogController(QDialog): self.ui.spinBoxParameter0.setValue(self.current_modulator.param_for_zero) self.ui.spinBoxParameter1.setValue(self.current_modulator.param_for_one) - elif self.ui.comboBoxModulationType.currentIndex() == 1: + elif self.__cur_selected_mod_type() in ("FSK", "GFSK"): self.ui.spinBoxParameter0.auto_suffix = True self.ui.spinBoxParameter1.auto_suffix = True self.ui.lParameterfor0.setText(self.tr("Frequency for 0:")) @@ -233,7 +238,7 @@ class ModulatorDialogController(QDialog): self.ui.spinBoxParameter0.setValue(self.current_modulator.param_for_zero) self.ui.spinBoxParameter1.setValue(self.current_modulator.param_for_one) - elif self.ui.comboBoxModulationType.currentIndex() == 2: + elif self.__cur_selected_mod_type() == "PSK": self.ui.spinBoxParameter0.auto_suffix = False self.ui.spinBoxParameter1.auto_suffix = False self.ui.lParameterfor0.setText(self.tr("Phase (degree) for 0:")) @@ -253,7 +258,8 @@ class ModulatorDialogController(QDialog): self.ui.spinBoxParameter0.setValue(self.current_modulator.param_for_zero) self.ui.spinBoxParameter1.setValue(self.current_modulator.param_for_one) - self.draw_modulated() + self.ui.spinBoxParameter0.editingFinished.emit() + self.ui.spinBoxParameter1.editingFinished.emit() def resizeEvent(self, event: QResizeEvent): @@ -476,7 +482,7 @@ class ModulatorDialogController(QDialog): self.autodetect_fsk_freqs() def autodetect_fsk_freqs(self): - if self.ui.comboBoxModulationType.currentIndex() != 1: + if self.__cur_selected_mod_type() not in ("FSK", "GFSK"): return try: diff --git a/src/urh/signalprocessing/Modulator.py b/src/urh/signalprocessing/Modulator.py index 0e06732d..ea4d465b 100644 --- a/src/urh/signalprocessing/Modulator.py +++ b/src/urh/signalprocessing/Modulator.py @@ -213,70 +213,6 @@ class Modulator(object): h = np.sqrt((2*np.pi)/(np.log(2))) * bt/ts * np.exp(-(((np.sqrt(2)*np.pi)/np.sqrt(np.log(2))*bt*k/self.samples_per_bit)**2)) return h / h.sum() - - def gauss_matlab(self, bt=0.5): - # https://github.com/rikrd/matlab/blob/master/signal/signal/gaussfir.m - symbol_range = 1 - filtLen = 2 * self.samples_per_bit * symbol_range + 1 - t = np.linspace(-symbol_range, symbol_range, filtLen) - alpha = np.sqrt(np.log(2) / 2) / (bt) - h = (np.sqrt(np.pi) / alpha) * np.exp(-(t * np.pi / alpha) ** 2) - return h/h.sum() - - - def gauss(self, n=11, sigma=1.0): - r = range(-int(n / 2), int(n / 2) + 1) - result = np.array([1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-float(x) ** 2 / (2 * sigma ** 2)) for x in r]) - return result / result.sum() - - - def gauss2(self, sigma=1.0, truncate=4.0): - sd = float(sigma) - # make the radius of the filter equal to truncate standard deviations - lw = int(truncate * sd + 0.5) - weights = [0.0] * (2 * lw + 1) - weights[lw] = 1.0 - sum = 1.0 - sd = sd * sd - # calculate the kernel: - for ii in range(1, lw + 1): - tmp = np.exp(-0.5 * float(ii * ii) / sd) - weights[lw + ii] = tmp - weights[lw - ii] = tmp - sum += 2.0 * tmp - for ii in range(2 * lw + 1): - weights[ii] /= sum - - return weights - - def gauss3(self, n=22, bt=0.5): - a = (1/bt) * np.sqrt(np.log10(2)/2) - r = range(-int(n / 2), int(n / 2) + 1) - result = np.array([np.sqrt(np.pi)/a * np.exp(-(np.pi ** 2 * x ** 2)/(a**2)) for x in r]) - return result / result.sum() - - def gunradio_gauss(self): - bit_len = 100 - gaussian_taps = self.firdes_gaussian(bit_len, 0.5, int(0.5*bit_len)) - sqwave = (1,) * bit_len - taps = np.convolve(np.array(gaussian_taps),np.array(sqwave)) - return taps - - def firdes_gaussian(self, samples_per_symbol, bt, ntaps): - taps = np.empty(ntaps, dtype=np.float32) - dt = 1/samples_per_symbol - s = 1.0/(np.sqrt(np.log(2.0)) / (2*np.pi*bt)) - t0 = -0.5 * ntaps - for i in range(ntaps): - t0 += 1 - ts = s*dt*t0 - taps[i] = np.exp(-0.5*ts*ts) - - taps /= taps.sum() - return taps - - - @staticmethod def get_value_with_suffix(value): if abs(value) >= 10 ** 9: