Skip to content

Commit 63d0421

Browse files
authored
Also handle resample to a lower frequency.
1 parent 6f06dee commit 63d0421

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

wfdb/processing/basic.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,39 @@ def resample_ann(tt, annsamp):
1010

1111
# Compute the new annotation indexes
1212

13-
result = numpy.zeros(len(tt), dtype='bool')
13+
tmp = numpy.zeros(len(tt), dtype='int16')
1414
j = 0
1515
tprec = tt[j]
1616
for i, v in enumerate(annsamp):
1717
while True:
1818
d = False
19+
if v < tprec:
20+
j -= 1
21+
tprec = tt[j]
22+
1923
if j+1 == len(tt):
20-
result[j] = 1
24+
tmp[j] += 1
2125
break
26+
2227
tnow = tt[j+1]
2328
if tprec <= v and v <= tnow:
2429
if v-tprec < tnow-v:
25-
result[j] = 1
30+
tmp[j] += 1
2631
else:
27-
result[j+1] = 1
32+
tmp[j+1] += 1
2833
d = True
2934
j += 1
3035
tprec = tnow
3136
if d:
3237
break
33-
return numpy.where(result==1)[0].astype('int64')
38+
39+
idx = numpy.where(tmp>0)[0].astype('int64')
40+
res = []
41+
for i in idx:
42+
for j in range(tmp[i]):
43+
res.append(i)
44+
assert len(res) == len(annsamp)
45+
return numpy.asarray(res, dtype='int64')
3446

3547

3648
def resample_sig(x, fs, fs_target):

0 commit comments

Comments
 (0)