예제 #1
0
def highpass_cnt(cnt, low_cut_off_hz, filt_order=3):
    if low_cut_off_hz is None:
        return cnt.copy()
    b,a = scipy.signal.butter(filt_order, low_cut_off_hz/(cnt.fs/2.0),btype='highpass')
    assert filter_is_stable(a)
    cnt_highpassed = lfilter(cnt,b,a)
    return cnt_highpassed
예제 #2
0
def bandstop_cnt(cnt, low_cut_hz, high_cut_hz, filt_order=3):
    nyq_freq = 0.5 * cnt.fs
    low = low_cut_hz / nyq_freq
    high = high_cut_hz / nyq_freq
    b, a = scipy.signal.butter(filt_order, [low, high], btype='bandstop')
    
    assert filter_is_stable(a)
    cnt_bandpassed = lfilter(cnt,b,a)
    return cnt_bandpassed
예제 #3
0
def bandstop_cnt(cnt, low_cut_hz, high_cut_hz, filt_order=3):
    nyq_freq = 0.5 * cnt.fs
    low = low_cut_hz / nyq_freq
    high = high_cut_hz / nyq_freq
    b, a = scipy.signal.butter(filt_order, [low, high], btype='bandstop')

    assert filter_is_stable(a)
    cnt_bandpassed = lfilter(cnt, b, a)
    return cnt_bandpassed
예제 #4
0
def highpass_filt_filt_cnt(cnt, low_cut_off_hz, filt_order=3):
    if (low_cut_off_hz is None) or (low_cut_off_hz == 0):
        log.info("Not doing any highpass, since low 0 or None")
        return cnt.copy()
    b, a = scipy.signal.butter(filt_order,
                               low_cut_off_hz / (cnt.fs / 2.0),
                               btype='highpass')
    assert filter_is_stable(a)
    cnt_highpassed = filtfilt(cnt, b, a)
    return cnt_highpassed
예제 #5
0
def lowpass_filt_filt_cnt(cnt, high_cut_off_hz, filt_order=3):
    if (high_cut_off_hz is None) or (high_cut_off_hz == cnt.fs):
        log.info(
            "Not doing any lowpass, since ince high cut hz is None or current fs"
        )
    b, a = scipy.signal.butter(filt_order,
                               high_cut_off_hz / (cnt.fs / 2.0),
                               btype='lowpass')
    assert filter_is_stable(a)
    cnt_lowpassed = filtfilt(cnt, b, a)
    return cnt_lowpassed
예제 #6
0
def bandpass_cnt(cnt, low_cut_hz, high_cut_hz, filt_order=3):
    """Bandpass cnt signal using butterworth filter.
    Uses lowpass in case low cut hz is exactly zero."""
    if (low_cut_hz == 0 or low_cut_hz == None) and (
        high_cut_hz == None):
        log.info("Not doing any bandpass, since low 0 or None and "
            "high None")
        return cnt.copy()
    if low_cut_hz == 0 or low_cut_hz == None:
        log.info("Using lowpass filter since low cut hz is 0 or None")
        return lowpass_cnt(cnt, high_cut_hz, filt_order=filt_order)
    if high_cut_hz == None:
        log.info("Using highpass filter since high cut hz is None")
        return highpass_cnt(cnt, low_cut_hz, filt_order=filt_order)
        
    nyq_freq = 0.5 * cnt.fs
    low = low_cut_hz / nyq_freq
    high = high_cut_hz / nyq_freq
    b, a = scipy.signal.butter(filt_order, [low, high], btype='bandpass')
    assert filter_is_stable(a), "Filter should be stable..."
    cnt_bandpassed = lfilter(cnt,b,a)
    return cnt_bandpassed
예제 #7
0
def bandpass_filt_filt_cnt(cnt, low_cut_hz, high_cut_hz, filt_order=3):
    """Bandpass cnt signal using butterworth filter.
    Uses lowpass in case low cut hz is exactly zero."""
    if (low_cut_hz == 0 or low_cut_hz == None) and (high_cut_hz == None
                                                    or high_cut_hz == cnt.fs):
        log.info("Not doing any bandpass, since low 0 or None and "
                 "high None or current fs")
        return cnt.copy()
    if low_cut_hz == 0 or low_cut_hz == None:
        log.info("Using lowpass filter since low cut hz is 0 or None")
        return lowpass_filt_filt_cnt(cnt, high_cut_hz, filt_order=filt_order)
    if high_cut_hz == None or high_cut_hz == cnt.fs:
        log.info(
            "Using highpass filter since high cut hz is None or current fs")
        return highpass_filt_filt_cnt(cnt, low_cut_hz, filt_order=filt_order)

    nyq_freq = 0.5 * cnt.fs
    low = low_cut_hz / nyq_freq
    high = high_cut_hz / nyq_freq
    b, a = scipy.signal.butter(filt_order, [low, high], btype='bandpass')
    assert filter_is_stable(a), "Filter should be stable..."
    cnt_bandpassed = filtfilt(cnt, b, a)
    return cnt_bandpassed
예제 #8
0
def highpass_filt_filt_cnt(cnt, low_cut_off_hz, filt_order=3):
    b,a = scipy.signal.butter(filt_order, low_cut_off_hz/(cnt.fs/2.0),btype='highpass')
    assert filter_is_stable(a)
    cnt_highpassed = filtfilt(cnt,b,a)
    return cnt_highpassed
예제 #9
0
def lowpass_cnt(cnt, high_cut_off_hz, filt_order=3):
    b,a = scipy.signal.butter(filt_order, high_cut_off_hz/(cnt.fs/2.0),
        btype='lowpass')
    assert filter_is_stable(a)
    cnt_lowpassed = lfilter(cnt,b,a)
    return cnt_lowpassed