def test_peaks_cleanecg(self): t, s = loadtxt(path + 'cleanecg.txt') pr = array([ 20, 87, 156, 225, 291, 355, 418, 482, 550, 624, 694, 764, 834, 905, 978 ]) assert_array_equal(pr, peaks(s, 75))
def BigPeaks(s, th, min_peak_distance=5, peak_return_percentage=0.1): p = peaks(s, th) pp = [] if len(p) == 0: pp = [] else: p = clean_near_peaks(s, p, min_peak_distance) if len(p) != 0: ars = argsort(s[p]) pp = p[ars] num_peaks_to_return = int(ceil(len(p) * peak_return_percentage)) pp = pp[-num_peaks_to_return:] else: pp == [] return pp
def _bigPeaks(s, th, min_peak_distance=5, peak_return_percentage=0.1): pp = [] if not list(s): return pp else: p = ni.peaks(s, th) if not list(p): return pp else: p = ni.clean_near_peaks(s, p, min_peak_distance) if not list(p): return pp else: ars = np.argsort(s[p]) pp = p[ars] num_peaks_to_return = int(np.ceil(len(p) * peak_return_percentage)) pp = pp[-num_peaks_to_return:] return pp
fs = 1000. t = arange(len(ecg)) / fs #Para retirar o DC e colocar o referencial na origem media = mean(ecg) ecg = ecg - media subplot(2, 1, 1) plot(t, ecg) title('ECG') xlabel('Time(ms)') ylabel('ECG(mV)') grid() counter = ni.peaks(ecg, 400) noise = zeros(len(ecg)) noise[min(counter):max(counter)] = 1 subplot(2, 1, 2) plot(t, noise) title('ECG NOISE DETECTOR') xlabel('Time(ms)') ylabel('Detection') axis([0, 100, -1, 1.5]) grid() plt.tight_layout() show()
def test_peaks_eda(self): t, s = loadtxt(path + 'eda.txt') pr = array([95, 146, 346]) assert_array_equal(pr, peaks(s, 600))
dnx = np.diff(nx) dny = np.diff(ny) # Detection of straight segments idx = dnx != 0 idy = dny == 0 vals = (idx * idy) + (~idx * ~idy) figure() subplot(131) plot(nx, ny) scatter(nx[vals], ny[vals], color='r') # Looping detection maxs_ny = ni.peaks(ny) mins_ny = ni.peaks(-ny) maxs_nx = ni.peaks(nx) mins_nx = ni.peaks(-nx) subplot(132) plot(nx, ny) scatter(nx[maxs_ny], ny[maxs_ny], color='r') scatter(nx[mins_ny], ny[mins_ny], color='g') scatter(nx[maxs_nx], ny[maxs_nx], color='b') scatter(nx[mins_nx], ny[mins_nx], color='k') e = hstack([maxs_ny, mins_ny, maxs_nx, mins_nx]) mask = hstack([ ones(len(maxs_ny)),
t=arange(len(ecg))/fs #Para retirar o DC e colocar o referencial na origem media=mean(ecg) ecg=ecg-media subplot(2,1,1) plot(t, ecg) title('ECG') xlabel('Time(ms)') ylabel('ECG(mV)') grid() counter = ni.peaks(ecg,400) noise=zeros(len(ecg)) noise[min(counter):max(counter)]=1 subplot(2,1,2) plot(t,noise) title('ECG NOISE DETECTOR') xlabel('Time(ms)') ylabel('Detection') axis([0, 100, -1, 1.5]) grid() plt.tight_layout() show()
def test_peaks_cleanecg(self): t, s = loadtxt(path + 'cleanecg.txt') pr = array([20, 87, 156, 225, 291, 355, 418, 482, 550, 624, 694, 764, 834, 905, 978]) assert_array_equal(pr, peaks(s, 75))