Skip to content

Commit 13a8948

Browse files
author
Benjamin Moody
committed
SignalMixin.smooth_frames: consolidate duplicated logic.
The logic for physical and digital cases is exactly the same except for the choice of input data and the resulting data type.
1 parent d02c478 commit 13a8948

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

wfdb/io/_signal.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -831,33 +831,26 @@ def smooth_frames(self, sigtype='physical'):
831831
tspf = sum(spf)
832832

833833
if sigtype == 'physical':
834-
n_sig = len(self.e_p_signal)
835-
sig_len = int(len(self.e_p_signal[0])/spf[0])
836-
signal = np.zeros((sig_len, n_sig), dtype='float64')
837-
838-
for ch in range(n_sig):
839-
if spf[ch] == 1:
840-
signal[:, ch] = self.e_p_signal[ch]
841-
else:
842-
for frame in range(spf[ch]):
843-
signal[:, ch] += self.e_p_signal[ch][frame::spf[ch]]
844-
signal[:, ch] = signal[:, ch] / spf[ch]
845-
834+
expanded_signal = self.e_p_signal
835+
output_dtype = np.dtype('float64')
846836
elif sigtype == 'digital':
847-
n_sig = len(self.e_d_signal)
848-
sig_len = int(len(self.e_d_signal[0])/spf[0])
849-
signal = np.zeros((sig_len, n_sig), dtype='int64')
850-
851-
for ch in range(n_sig):
852-
if spf[ch] == 1:
853-
signal[:, ch] = self.e_d_signal[ch]
854-
else:
855-
for frame in range(spf[ch]):
856-
signal[:, ch] += self.e_d_signal[ch][frame::spf[ch]]
857-
signal[:, ch] = signal[:, ch] / spf[ch]
837+
expanded_signal = self.e_d_signal
838+
output_dtype = np.dtype('int64')
858839
else:
859840
raise ValueError("sigtype must be 'physical' or 'digital'")
860841

842+
n_sig = len(expanded_signal)
843+
sig_len = int(len(expanded_signal[0])/spf[0])
844+
signal = np.zeros((sig_len, n_sig), dtype=output_dtype)
845+
846+
for ch in range(n_sig):
847+
if spf[ch] == 1:
848+
signal[:, ch] = expanded_signal[ch]
849+
else:
850+
for frame in range(spf[ch]):
851+
signal[:, ch] += expanded_signal[ch][frame::spf[ch]]
852+
signal[:, ch] = signal[:, ch] / spf[ch]
853+
861854
return signal
862855

863856

0 commit comments

Comments
 (0)