Skip to content

Commit 3fd3cc7

Browse files
committed
Fixes downsample error MIT-LCP#249
Fixes error when downsampling single channel if NaN values are present. This was a Scipy issue so extra pre-processing and input validation was done to help safe-guard against this issue re-occuring in the future. Fixes MIT-LCP#249.
1 parent 1dd4b5c commit 3fd3cc7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

wfdb/processing/basic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
from scipy import signal
3+
import pandas as pd
34
import pdb
45

56
from wfdb.io.annotation import Annotation
@@ -91,6 +92,9 @@ def resample_sig(x, fs, fs_target):
9192
return x, t
9293

9394
new_length = int(x.shape[0]*fs_target/fs)
95+
# Resample the array if NaN values are present
96+
if np.isnan(x).any():
97+
x = pd.Series(x.reshape((-1,))).interpolate().values
9498
resampled_x, resampled_t = signal.resample(x, num=new_length, t=t)
9599
assert resampled_x.shape == resampled_t.shape and resampled_x.shape[0] == new_length
96100
assert np.all(np.diff(resampled_t) > 0)

0 commit comments

Comments
 (0)