def test_check_peak(self):
        data = [0, 1, 2, 1, 0]
        self.assertTrue(check_peak(data))  # TODO: Change these to datapoints

        data = [0, 1, 0, 1, 0]
        self.assertFalse(check_peak(data))  # TODO: Change these to datapoints

        data = [0, 1, 2, 3, 4, 3, 2, 1]
        self.assertTrue(check_peak(data))  # TODO: Change these to datapoints

        data = [0, 1]
        self.assertFalse(check_peak(data))  # TODO: Change these to datapoints
Пример #2
0
    def test_check_peak(self):
        data = [0, 1, 2, 1, 0]
        self.assertTrue(check_peak(data))

        data = [0, 1, 0, 1, 0]
        self.assertFalse(check_peak(data))

        data = [0, 1, 2, 3, 4, 3, 2, 1]
        self.assertTrue(check_peak(data))

        data = [0, 1]
        self.assertRaises(Exception, check_peak, data)
Пример #3
0
	def test_detect_rpeak(self, threshold: float = .5):
		sample = np.array([i.sample for i in self.ecg])
		blackman_win_len = np.ceil(self._fs / 5)
		y = compute_moving_window_int(sample, self._fs, blackman_win_len)

		peak_location_values = [(i, y[i]) for i in range(2, len(y) - 1) if check_peak(y[i - 2:i + 3])]
		peak_location = [i[0] for i in peak_location_values]

		running_rr_avg = sum(np.diff(peak_location)) / (len(peak_location) - 1)
		rpeak_temp1 = compute_r_peaks(threshold, running_rr_avg, y, peak_location_values)

		first_index_file = os.path.join(os.path.dirname(__file__), 'res/testmatlab_firstindex.csv')
		peak_index1_from_data = np.genfromtxt(first_index_file, delimiter=',')
		test_result = (len(list(set(rpeak_temp1) & set(peak_index1_from_data - 1))) * 100) / len(rpeak_temp1)
		self.assertGreaterEqual(test_result, 99, 'Peaks after adaptive threshold is less than a 99 percent match')

		rpeak_temp2 = remove_close_peaks(rpeak_temp1, sample, self._fs)
		second_index_file = os.path.join(os.path.dirname(__file__), 'res/testmatlab_secondindex.csv')
		peak_index2_from_data = np.genfromtxt(second_index_file, delimiter=',')
		test_result = (len(list(set(rpeak_temp2) & set(peak_index2_from_data - 1))) * 100) / len(rpeak_temp2)
		self.assertGreaterEqual(test_result, 99, 'Peaks after removing close peaks is less than a 99 percent match')

		index = confirm_peaks(rpeak_temp2, sample, self._fs)
		final_index_file = os.path.join(os.path.dirname(__file__), 'res/testmatlab_finalindex.csv')
		peak_index3_from_data = np.genfromtxt(final_index_file, delimiter=',')
		test_result = (len(list(set(index) & set(peak_index3_from_data - 1))) * 100) / len(index)
		self.assertGreaterEqual(test_result, 99, 'Peaks after confirmation is less than a 99 percent match')