def filterResp(self, x):
        # fc = 2.  # Cutoff frequency as a fraction of the sampling rate (in (0, 0.5)).
        # b = 0.08  # 120 taps
        # N = int(np.ceil((4 / b)))
        # if not N % 2: N += 1  # Make sure that N is odd.
        # n = np.arange(N)
        #
        # # Compute sinc filter.
        # h = np.sinc(2 * fc * (n - (N - 1) / 2))
        #
        # # Compute Blackman window.
        # w = 0.42 - 0.5 * np.cos(2 * np.pi * n / (N - 1)) + \
        #     0.08 * np.cos(4 * np.pi * n / (N - 1))
        #
        # # Multiply sinc filter by window.
        # h = h * w
        #
        # # Normalize to get unity gain.
        # h = h / np.sum(h)
        #
        # return np.convolve(x, h, mode="same")

        filtered, _, _ = st.filter_signal(signal=x,
                                          ftype='butter',
                                          band='bandpass',
                                          order=2,
                                          frequency=[0.1, 0.35],
                                          sampling_rate=self.fs)

        return filtered
Exemple #2
0
def one_lead_ecg_filter(signal, sampling_rate=500):
    filtered, _, _ = st.filter_signal(signal=signal,
                                      ftype='FIR',
                                      band='bandpass',
                                      order=int(0.3 * sampling_rate),
                                      frequency=[3, 45],
                                      sampling_rate=sampling_rate)
    return filtered
    def filterECG(self, x):
        order = int(0.3 * self.fs)
        filtered, _, _ = st.filter_signal(signal=x,
                                          ftype='FIR',
                                          band='bandpass',
                                          order=order,
                                          frequency=[3, 45],
                                          sampling_rate=self.fs)

        return filtered
Exemple #4
0
 def filterPPG(self, x):
     # filter signal
     # filtered = butterBandpassFilter(x, lowcut=.5, highcut=5., order=4, fs=self.fs)
     filtered, _, _ = st.filter_signal(signal=x,
                                       ftype='butter',
                                       band='bandpass',
                                       order=4,
                                       frequency=[1, 7],
                                       sampling_rate=self.fs)
     return filtered
Exemple #5
0
    def filterEDA(self, x):
        filtered, _, _ = st.filter_signal(signal=x,
                                          ftype='butter',
                                          band='lowpass',
                                          order=2,
                                          frequency=15,
                                          sampling_rate=self.fs)
        sm_size = int(0.75 * self.fs)
        filtered, _ = st.smoother(signal=filtered,
                                  kernel='boxzen',
                                  size=sm_size,
                                  mirror=True)

        return filtered
Exemple #6
0
def _positive_peaks(raw_ECG_data, sampling_rate=1000, method='wavelet'):
    """Process a raw ECG signal and extracts R peaks.    
    Parameters
    ----------
    signal : array
        Raw ECG signal.
    sampling_rate : int, float, optional
        Sampling frequency (Hz).
    method: 'wavelet' or 'hamilton'. Hamilton will find R-peaks based on the 
        iterative hamilton segmenter method. Wavelet find find r-peaks based
        on convolution of the signal with a qrs-complex-shaped wavelet.
    Returns
    -------
    positive_peaks : array
        Positive-peak location indices. 
    """

    if method == 'hamilton':
        order = int(0.3 * sampling_rate)
        filtered, _, _ = st.filter_signal(raw_ECG_data,
                                          ftype='FIR',
                                          band='bandpass',
                                          order=order,
                                          frequency=[3, 45],
                                          sampling_rate=sampling_rate)
        positive_peaks, = biosppy.signals.ecg.hamilton_segmenter(
            filtered, sampling_rate=1000.0)
        positive_peaks, = biosppy.signals.ecg.correct_rpeaks(
            signal=filtered,
            rpeaks=positive_peaks,
            sampling_rate=1000,
            tol=0.05)
        # plt.plot(raw_ECG_data)
        # plt.plot(positive_peaks, raw_ECG_data[positive_peaks], 'or')
    elif method == 'wavelet':
        wv = pywt.Wavelet('sym4')
        _, qrs, _ = wv.wavefun(level=5)
        cv = signal.fftconvolve(raw_ECG_data, qrs, mode='same')
        positive_peaks = signal.find_peaks(np.abs(cv),
                                           distance=int(sampling_rate / 2),
                                           prominence=200)[0]
        # plt.figure()
        # plt.plot(cv)
        # plt.plot(raw_ECG_data)
        # plt.plot(positive_peaks, cv[positive_peaks], 'or')
    else:
        raise ValueError('no valid method selected')

    return positive_peaks