Skip to content

Commit 374819a

Browse files
committed
correct variable name. fixes MIT-LCP#98
1 parent bf0dc27 commit 374819a

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

wfdb/io/_signal.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -439,25 +439,30 @@ def dac(self, expanded=False, return_res=64, inplace=False):
439439
return p_signal
440440

441441

442-
# Compute appropriate gain and baseline parameters given the physical signal and the fmts
443-
# self.fmt must be a list with length equal to the number of signal channels in self.p_signal
442+
444443
def calc_adc_params(self):
445-
446-
# digital - baseline / gain = physical
447-
# physical * gain + baseline = digital
444+
"""
445+
Compute appropriate gain and baseline parameters given the physical
446+
signal and the fmts.
448447
448+
digital - baseline / gain = physical
449+
physical * gain + baseline = digital
450+
"""
449451
gains = []
450452
baselines = []
451453

452-
# min and max ignoring nans, unless whole channel is nan. Should suppress warning message.
454+
# min and max ignoring nans, unless whole channel is nan.
455+
# Should suppress warning message.
453456
minvals = np.nanmin(self.p_signal, axis=0)
454457
maxvals = np.nanmax(self.p_signal, axis=0)
455458

456459
dnans = digi_nan(self.fmt)
457460

458461
for ch in range(0, np.shape(self.p_signal)[1]):
459-
dmin, dmax = digi_bounds(self.fmt[ch]) # Get the minimum and maximum (valid) storage values
460-
dmin = dmin + 1 # add 1 because the lowest value is used to store nans
462+
# Get the minimum and maximum (valid) storage values
463+
dmin, dmax = digi_bounds(self.fmt[ch])
464+
# add 1 because the lowest value is used to store nans
465+
dmin = dmin + 1
461466
dnan = dnans[ch]
462467

463468
pmin = minvals[ch]
@@ -471,21 +476,23 @@ def calc_adc_params(self):
471476
baseline = 1
472477
# If the signal is just one value, store all values as digital 1.
473478
elif pmin == pmax:
474-
if minval ==0:
479+
if pmin == 0:
475480
gain = 1
476481
baseline = 1
477482
else:
478-
gain = 1/minval # wait.. what if minval is 0...
483+
gain = 1 / pmin
479484
baseline = 0
485+
# Regular mixed signal case
486+
# Todo:
480487
else:
481-
482-
gain = (dmax-dmin) / (pmax - pmin)
483-
baseline = dmin - gain * pmin
488+
gain = (dmax-dmin) / (pmax-pmin)
489+
baseline = dmin - gain*pmin
484490

485-
# What about roundoff error? Make sure values don't map to beyond range.
491+
# What about roundoff error? Make sure values don't map to beyond
492+
# range.
486493
baseline = int(baseline)
487494

488-
# WFDB library limits...
495+
# WFDB library limits...
489496
if abs(gain)>214748364 or abs(baseline)>2147483648:
490497
raise Exception('adc_gain and baseline must have magnitudes < 214748364')
491498

0 commit comments

Comments
 (0)