Esempio n. 1
0
    def _update_win_fft(self):
        """ Update window type for FirWin """
        self.alg = str(self.cmb_firwin_alg.currentText())
        self.fir_window_name = qget_cmb_box(self.cmb_firwin_win, data=False)
        self.win = calc_window_function(self.win_dict,
                                        self.fir_window_name,
                                        N=self.N,
                                        sym=True)
        n_par = self.win_dict['n_par']

        self.lblWinPar1.setVisible(n_par > 0)
        self.ledWinPar1.setVisible(n_par > 0)
        self.lblWinPar2.setVisible(n_par > 1)
        self.ledWinPar2.setVisible(n_par > 1)

        if n_par > 0:
            self.lblWinPar1.setText(
                to_html(self.win_dict['par'][0]['name'] + " =", frmt='bi'))
            self.ledWinPar1.setText(str(self.win_dict['par'][0]['val']))
            self.ledWinPar1.setToolTip(self.win_dict['par'][0]['tooltip'])

        if n_par > 1:
            self.lblWinPar2.setText(
                to_html(self.win_dict['par'][1]['name'] + " =", frmt='bi'))
            self.ledWinPar2.setText(str(self.win_dict['par'][1]['val']))
            self.ledWinPar2.setToolTip(self.win_dict['par'][1]['tooltip'])

        # sig_tx -> select_filter -> filter_specs
        self.sig_tx.emit({'sender': __name__, 'filt_changed': 'firwin'})
Esempio n. 2
0
 def BPman(self, fil_dict):
     self._get_params(fil_dict)
     if not self._test_N():
         return -1
     self.fir_window = calc_window_function(self.win_dict, self.fir_window_name,
                                     N=self.N, sym=True)
     self._save(fil_dict, self.firwin(self.N, [fil_dict['F_C'], fil_dict['F_C2']],
                         window = self.fir_window, pass_zero=False, nyq = 0.5))
Esempio n. 3
0
 def BSman(self, fil_dict):
     self._get_params(fil_dict)
     self.N = round_odd(self.N)  # enforce odd order
     if not self._test_N():
         return -1
     self.fir_window = calc_window_function(self.win_dict, self.fir_window_name,
                                     N=self.N, sym=True)
     self._save(fil_dict, self.firwin(self.N, [fil_dict['F_C'], fil_dict['F_C2']],
                         window = self.fir_window, pass_zero=True, nyq = 0.5))
Esempio n. 4
0
 def LPmin(self, fil_dict):
     self._get_params(fil_dict)
     self.N = self._firwin_ord([self.F_PB, self.F_SB], [1, 0],
                              [self.A_PB, self.A_SB], alg = self.alg)
     if not self._test_N():
         return -1
     self.fir_window = calc_window_function(self.win_dict, self.fir_window_name,
                                     N=self.N, sym=True)
     fil_dict['F_C'] = (self.F_SB + self.F_PB)/2 # use average of calculated F_PB and F_SB
     self._save(fil_dict, self.firwin(self.N, fil_dict['F_C'], 
                                    window = self.fir_window, nyq = 0.5))
Esempio n. 5
0
 def HPmin(self, fil_dict):
     self._get_params(fil_dict)
     N = self._firwin_ord([self.F_SB, self.F_PB], [0, 1],
                         [self.A_SB, self.A_PB], alg = self.alg)
     self.N = round_odd(N)  # enforce odd order
     if not self._test_N():
         return -1
     self.fir_window = calc_window_function(self.win_dict, self.fir_window_name,
                                     N=self.N, sym=True)
     fil_dict['F_C'] = (self.F_SB + self.F_PB)/2 # use average of calculated F_PB and F_SB
     self._save(fil_dict, self.firwin(self.N, fil_dict['F_C'], 
                 window = self.fir_window, pass_zero=False, nyq = 0.5))
Esempio n. 6
0
 def BSmin(self, fil_dict):
     self._get_params(fil_dict)
     N = remezord([self.F_PB, self.F_SB, self.F_SB2, self.F_PB2], [1, 0, 1],
         [self.A_PB, self.A_SB, self.A_PB2], fs = 1, alg = self.alg)[0]
     self.N = round_odd(N)  # enforce odd order
     if not self._test_N():
         return -1
     self.fir_window = calc_window_function(self.win_dict, self.fir_window_name,
                                     N=self.N, sym=True)
     fil_dict['F_C'] = (self.F_SB + self.F_PB)/2 # use average of calculated F_PB and F_SB
     fil_dict['F_C2'] = (self.F_SB2 + self.F_PB2)/2 # use average of calculated F_PB and F_SB
     self._save(fil_dict, self.firwin(self.N, [fil_dict['F_C'], fil_dict['F_C2']],
                         window = self.fir_window, pass_zero=True, nyq = 0.5))
Esempio n. 7
0
    def BPmin(self, fil_dict):
        self._get_params(fil_dict)
        self.N = remezord([self.F_SB, self.F_PB, self.F_PB2, self.F_SB2], [0, 1, 0],
            [self.A_SB, self.A_PB, self.A_SB2], Hz = 1, alg = self.alg)[0]
        if not self._test_N():
            return -1
        self.fir_window = calc_window_function(self.win_dict, self.fir_window_name,
                                        N=self.N, sym=True)

        fil_dict['F_C'] = (self.F_SB + self.F_PB)/2 # use average of calculated F_PB and F_SB
        fil_dict['F_C2'] = (self.F_SB2 + self.F_PB2)/2 # use average of calculated F_PB and F_SB
        self._save(fil_dict, self.firwin(self.N, [fil_dict['F_C'], fil_dict['F_C2']],
                            window = self.fir_window, pass_zero=False, nyq = 0.5))
Esempio n. 8
0
    def _update_win_fft(self, arg=None, emit=True):
        """
        Update window type for FFT  with different arguments:

        - signal-slot connection to combo-box -> index (int), absorbed by `arg`
                                                 emit is not set -> emit=True
        - called by _read_param() -> empty -> emit=True
        - called by update_N(emit=False)

        """
        if not isinstance(emit, bool):
            logger.error("update win: emit={0}".format(emit))
        self.window_name = qget_cmb_box(self.cmb_win_fft, data=False)
        self.win = calc_window_function(self.win_dict,
                                        self.window_name,
                                        N=self.N,
                                        sym=False)

        n_par = self.win_dict['n_par']

        self.lblWinPar1.setVisible(n_par > 0)
        self.ledWinPar1.setVisible(n_par > 0)
        self.lblWinPar2.setVisible(n_par > 1)
        self.ledWinPar2.setVisible(n_par > 1)

        if n_par > 0:
            self.lblWinPar1.setText(
                to_html(self.win_dict['par'][0]['name'] + " =", frmt='bi'))
            self.ledWinPar1.setText(str(self.win_dict['par'][0]['val']))
            self.ledWinPar1.setToolTip(self.win_dict['par'][0]['tooltip'])

        if n_par > 1:
            self.lblWinPar2.setText(
                to_html(self.win_dict['par'][1]['name'] + " =", frmt='bi'))
            self.ledWinPar2.setText(str(self.win_dict['par'][1]['val']))
            self.ledWinPar2.setToolTip(self.win_dict['par'][1]['tooltip'])

        self.nenbw = self.N * np.sum(np.square(self.win)) / (np.square(
            np.sum(self.win)))

        self.cgain = np.sum(self.win) / self.N  # coherent gain
        self.win /= self.cgain  # correct gain for periodic signals

        # only emit a signal for local triggers to prevent infinite loop:
        # - signal-slot connection passes a bool or an integer
        # - local function calls don't pass anything
        if emit is True:
            self.sig_tx.emit({'sender': __name__, 'ui_changed': 'win'})
        # ... but always notify the FFT widget via sig_tx_fft
        self.sig_tx_fft.emit({'sender': __name__, 'view_changed': 'win'})
Esempio n. 9
0
    def calc_win(self):
        """
        (Re-)Calculate the window and its FFT
        """
        self.led_N.setEnabled(not self.chk_auto_N.isChecked())

        if not self.chk_auto_N.isChecked():
            self.N = safe_eval(self.led_N.text(),
                               self.N,
                               sign='pos',
                               return_type='int')

    # else:
    #self.N = self.win_dict['win_len']

        self.led_N.setText(str(self.N))

        self.n = np.arange(self.N)

        self.win = calc_window_function(self.win_dict,
                                        self.win_dict['name'],
                                        self.N,
                                        sym=self.sym)

        self.nenbw = self.N * np.sum(np.square(self.win)) / (np.square(
            np.sum(self.win)))
        self.cgain = np.sum(self.win) / self.N

        self.F = fftfreq(self.N * self.pad,
                         d=1. / fb.fil[0]['f_S'])  # use zero padding
        self.Win = np.abs(fft(self.win, self.N * self.pad))
        if self.chk_norm_f.isChecked():
            self.Win /= (self.N * self.cgain
                         )  # correct gain for periodic signals (coherent gain)

        first_zero = argrelextrema(self.Win[:(self.N * self.pad) // 2],
                                   np.less)
        if np.shape(first_zero)[1] > 0:
            first_zero = first_zero[0][0]
            self.first_zero_f = self.F[first_zero]
            self.sidelobe_level = np.max(
                self.Win[first_zero:(self.N * self.pad) // 2])
        else:
            self.first_zero_f = np.nan
            self.sidelobe_level = 0