Пример #1
0
    def __getitem__(self, index):
        assert (index < self._dataset_size)

        #if self._is_for_train:  # random
        #    index = random.randint(0, self._dataset_size-1)

        # get sample data
        data = self._data[index] / 1000
        data = list(data)

        data_reverse = copy.deepcopy(data)
        data_reverse.reverse()

        filt_rri1 = list(moving_average(RRi(data), order=1))
        filt_rri2 = list(moving_average(RRi(data), order=2))
        filt_rri3 = list(moving_average(RRi(data), order=3))

        filt_rri1_reverse = copy.deepcopy(filt_rri1)
        filt_rri2_reverse = copy.deepcopy(filt_rri2)
        filt_rri3_reverse = copy.deepcopy(filt_rri3)
        filt_rri1_reverse.reverse()
        filt_rri2_reverse.reverse()
        filt_rri3_reverse.reverse()

        order_data = [filt_rri1, filt_rri2, filt_rri3]
        order_data_reverse = [
            filt_rri1_reverse, filt_rri2_reverse, filt_rri3_reverse
        ]

        label = int(self._label[index])
        subject = self._subject[index]

        mean = self._mean_train[index]
        sdnn = self._sdnn_train[index]
        pnn50 = self._pnn50_train[index]
        rmssd = self._rmssd_train[index]
        lnrmssd = self._lnrmssd_train[index]
        vlf = self._vlf_train[index]
        lf = self._lf_train[index]
        hf = self._hf_train[index]
        rlh = self._rlh_train[index]

        features = list(np.stack((mean, sdnn, pnn50, rmssd, lnrmssd, \
                             vlf, lf, hf, rlh )))

        makeup_length = 512 - len(data)
        if len(data) > 512:
            data = data[:512]
        else:
            data.extend(0 for _ in range(makeup_length))

        return data, data_reverse, order_data, order_data_reverse, label, subject, features
Пример #2
0
    def test_moving_average_order_3(self):
        fake_rri = np.array([810, 830, 860, 790, 804])

        rri_filt = moving_average(fake_rri, order=3)

        expected = [810, 833.33, 826.66, 818, 804]
        np.testing.assert_almost_equal(rri_filt, expected, decimal=2)
Пример #3
0
    def test_moving_average_order_5(self):
        fake_rri = np.array([810, 830, 860, 790, 804, 801, 800])

        rri_filt = moving_average(fake_rri, order=5)

        expected = [810, 830, 818.79, 817.0, 811.0, 801, 800]
        np.testing.assert_almost_equal(rri_filt, expected, decimal=2)
Пример #4
0
 def preprocess_hr_signal(raw_signal,
                          fs,
                          sig_len,
                          desired_fs: int = 1,
                          interval: int = 1):
     """
     correct sampling bias by making a frequency shift, moving average filter and threshold LPF
     :param raw_signal: signal to be preprocessed
     :param fs: the raw_signal's sampling frequency
     :param sig_len: raw signal's number of samples
     :param desired_fs: desired sampling frequency
     :param interval: window for moving average filter
     :return: processed signal
     """
     # interval in hours
     signal = Waveforms.frequency_shift(raw_signal, sig_len, fs, desired_fs)
     signal = pos_sig(signal)
     if np.isnan(signal).all():
         return np.nan
     signal = RRi(signal)
     window = desired_fs * interval * 3600
     return threshold_filter(moving_average(signal, window),
                             threshold='strong')