Skip to content

Commit 587539c

Browse files
committed
get power line frequency value
1 parent a00b0a3 commit 587539c

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/explorepy/explore.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ def record_data(
182182
if file_type not in ['edf', 'csv']:
183183
raise ValueError(
184184
'{} is not a supported file extension!'.format(file_type))
185+
185186
if imp_mode:
187+
if not self.stream_processor.is_imp_running():
188+
raise ValueError('Impedance measurement not running!')
186189
if file_type == 'edf':
187190
raise ValueError(
188191
'{} is not a supported file extension for recording impedance!'.format(file_type))
189-
if notch_freq is None:
190-
raise ValueError(
191-
'Missing notch frequency argument, please provide the notch frequency to get live impedance values')
192+
193+
notch_freq = self.stream_processor.get_power_line_freq() or 50
192194

193195
duration = self._check_duration(duration)
194196

src/explorepy/filters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, cutoff_freq, filter_type, s_rate, n_chan, order=5):
3131
self.s_rate = float(s_rate)
3232
self.filter_type = filter_type
3333
self.filter_param = None
34+
self.cutoff_freq = cutoff_freq
3435
order = 2 if self.s_rate > 1000 else order
3536
a, b, zi = self.get_filter_coeffs(cutoff_freq, filter_type, s_rate, n_chan, order)
3637
self.filter_param = {'a': a, 'b': b, 'zi': zi}
@@ -110,6 +111,9 @@ def get_notch_coeffs(cutoff, nyquist, n_channels, order, quality=30, imp_mode=Fa
110111
zi = np.zeros(shape=(n_channels, 2))
111112
return a, b, zi
112113

114+
def get_cutoff_freq(self):
115+
return self.cutoff_freq
116+
113117
def apply(self, input_data, in_place=True):
114118
"""Apply filter
115119

src/explorepy/stream_processor.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def process(self, packet):
314314
missing_timestamps = self.fill_missing_packet(packet)
315315
self._update_last_time_point(packet, received_time)
316316
self.packet_count += 1
317-
if self._is_imp_mode and self.imp_calculator:
317+
if self.is_imp_running():
318318
packet_imp = self.imp_calculator.measure_imp(
319319
packet=copy.deepcopy(packet))
320320
if packet_imp is not None:
@@ -459,9 +459,10 @@ def imp_initialize(self, notch_freq, calibration=False):
459459
cmd = ZMeasurementEnable()
460460
if self.configure_device(cmd):
461461
self.imp_calib_info['calibration'] = calibration
462+
self._add_notch_filter()
462463
self.imp_calculator = ImpedanceMeasurement(device_info=self.device_info,
463464
calib_param=self.imp_calib_info,
464-
notch_freq=notch_freq)
465+
notch_freq=self.get_power_line_freq())
465466
self._is_imp_mode = True
466467
else:
467468
raise ConnectionError('Device configuration process failed!')
@@ -475,6 +476,7 @@ def disable_imp(self):
475476
return True
476477
print("WARNING: Couldn't disable impedance measurement mode. "
477478
"Please restart your device manually.")
479+
self._notch_filter = None
478480
return False
479481

480482
def set_marker(self, marker_string, time_lsl=None, name='mkr', soft_marker=True):
@@ -596,3 +598,14 @@ def _add_notch_filter(self):
596598
s_rate=250,
597599
n_chan=SettingsManager(self.device_info['device_name']).get_channel_count()
598600
)
601+
602+
def is_imp_running(self):
603+
return self._is_imp_mode and self.imp_calculator
604+
605+
def get_power_line_freq(self):
606+
match = next(
607+
(item for item in self.filters if item.filter_type == 'notch'),
608+
None
609+
)
610+
611+
return match.cutoff_freq if match else None

0 commit comments

Comments
 (0)