Beispiel #1
0
def bandpass_kaiser(ntaps, lowcut, highcut, fs, width):
    nyq = 0.5 * fs
    atten = kaiser_atten(ntaps, width / nyq)
    beta = kaiser_beta(atten)
    taps = firwin(ntaps, [lowcut, highcut], nyq=nyq, pass_zero=False,
                  window=('kaiser', beta), scale=False)
    return taps
def bandpass_kaiser(ntaps, lowcut, highcut, fs, width):
    nyq = 0.5 * fs
    atten = kaiser_atten(ntaps, width / nyq)
    beta = kaiser_beta(atten)
    taps = firwin(ntaps, [lowcut, highcut], nyq=nyq, pass_zero=False,
                  window=('kaiser', beta), scale=False)
    return taps
 def bandpass_kaiser(self, channel,freqs=(1, 15)):
     ntaps = 16
     nyq = 0.5 * self.rate
     width = 1.6
     atten = signal.kaiser_atten(ntaps, width / nyq)
     beta = signal.kaiser_beta(atten)
     taps = signal.firwin(ntaps, [freqs[0], freqs[1]], nyq=nyq, pass_zero=False,
                   window=('kaiser', beta), scale=False)
     newsig = signal.filtfilt(taps_kaiser16, 1.0, self.single_sweep_data[channel], padlen=500)
     return newsig
Beispiel #4
0
def bandpass_kaiser(ntaps, lowcut, highcut, fs, width):
    nyq = 0.5 * fs
    atten = kaiser_atten(ntaps, width / nyq)
    beta = kaiser_beta(atten)
    taps = firwin(
        ntaps,
        [lowcut, highcut],
        nyq=nyq,
        pass_zero="bandpass",
        window=("kaiser", beta),
        scale=True,
    )
    return taps
 def bandpass_kaiser(self, channel, freqs=(1, 15)):
     ntaps = 16
     nyq = 0.5 * self.rate
     width = 1.6
     atten = signal.kaiser_atten(ntaps, width / nyq)
     beta = signal.kaiser_beta(atten)
     taps = signal.firwin(ntaps, [freqs[0], freqs[1]],
                          nyq=nyq,
                          pass_zero=False,
                          window=('kaiser', beta),
                          scale=False)
     newsig = signal.filtfilt(taps_kaiser16,
                              1.0,
                              self.single_sweep_data[channel],
                              padlen=500)
     return newsig
def test_kaiser_atten():
    a = kaiser_atten(1, 1.0)
    assert_equal(a, 7.95)
    a = kaiser_atten(2, 1/np.pi)
    assert_equal(a, 2.285 + 7.95)
Beispiel #7
0
def construct_fir_filter(rate, frequencies, gains, order, phase, window,
                         design):
    """ Construct coeffs of FIR filter.

    Args:
        rate (float): Nominal sampling rate of the input data.
        order (int): Filter order
        frequencies (list): Transition frequencies in Hz.
        design (str|'firwin2'): Design of the transfert function of the filter.
        phase (str|`linear`): Phase response ("zero", "zero-double" or "minimum").
        window (float|`hamming`): The window to use in FIR design, ("hamming", "hann", or "blackman").

    Returns:
        array h. FIR coeffs.

    Notes:

        Adapted from mne.filters, see the documentation of:

        * `mne.filters <https://martinos.org/mne/stable/generated/mne.filter.construct_fir_filter.html>`_
        * `scipy.signal.firwin2 <https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.firwin2.html>`_



    """
    nyq = rate / 2.
    if design == 'firwin2':
        from scipy.signal import firwin2 as design
    else:
        # not implemented yet
        raise ValueError(
            'firwin, remez and firls have not been implemented yet ')

    # issue a warning if attenuation is less than this
    min_att_db = 12 if phase == 'minimum' else 20

    if frequencies[0] != 0 or frequencies[-1] != nyq:
        raise ValueError(
            'freq must start at 0 and end an Nyquist (%s), got %s' %
            (nyq, frequencies))
    gains = np.array(gains)

    if window == "kaiser":
        diffs = np.diff(frequencies)
        width = min(diffs[diffs > 0])
        beta = signal.kaiser_beta(signal.kaiser_atten(order, width / nyq))
        window = ("kaiser", beta)

    # check zero phase length
    N = int(order)
    if N % 2 == 0:
        if phase == 'zero':
            LOGGER.info('filter_length must be odd if phase="zero", '
                        'got %s' % N)
            N += 1
        elif phase == 'zero-double' and gains[-1] == 1:
            N += 1
    # construct symmetric (linear phase) filter
    if phase == 'minimum':
        h = design(N * 2 - 1, frequencies, gains, fs=rate, window=window)
        h = signal.minimum_phase(h)
    else:
        h = design(N, frequencies, gains, fs=rate, window=window)
    assert h.size == N
    att_db, att_freq = _filter_attenuation(h, frequencies, gains)
    if phase == 'zero-double':
        att_db += 6
    if att_db < min_att_db:
        att_freq *= rate / 2.
        LOGGER.info('Attenuation at stop frequency %0.1fHz is only %0.1fdB. '
                    'Increase filter_length for higher attenuation.' %
                    (att_freq, att_db))
    return h
def test_kaiser_atten():
    a = kaiser_atten(1, 1.0)
    assert_equal(a, 7.95)
    a = kaiser_atten(2, 1/np.pi)
    assert_equal(a, 2.285 + 7.95)
Beispiel #9
0
 def cpu_version(self, numtaps, width):
     return signal.kaiser_atten(numtaps, width)