Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param order: filter order
:type order: int
:param filter_type: filter type from special enum
:type filter_type: int
:param ripple: ripple value for Chebyshev filter
:type ripple: float
"""
if not isinstance (sampling_rate, int):
raise BrainFlowError ('wrong type for sampling rate', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (filter_type, int):
raise BrainFlowError ('wrong type for filter type', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
res = DataHandlerDLL.get_instance ().perform_bandstop (data, data.shape[0], sampling_rate, center_freq, band_width, order, filter_type, ripple)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to apply band stop filter', res)
:type data: 1d numpy array
:param period: downsampling period
:type period: int
:param operation: int value from AggOperation enum
:type operation: int
:return: downsampled data
:rtype: 1d numpy array
"""
if not isinstance (period, int):
raise BrainFlowError ('wrong type for period', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (operation, int):
raise BrainFlowError ('wrong type for operation', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if period <= 0:
raise BrainFlowError ('Invalid value for period', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
downsampled_data = numpy.zeros (int (data.shape[0] / period)).astype (numpy.float64)
res = DataHandlerDLL.get_instance ().perform_downsampling (data, data.shape[0], period, operation, downsampled_data)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to perform downsampling', res)
return downsampled_data
def perform_downsampling (cls, data, period, operation):
"""perform data downsampling, it doesnt apply lowpass filter for you, it just aggregates several data points
:param data: initial data
:type data: 1d numpy array
:param period: downsampling period
:type period: int
:param operation: int value from AggOperation enum
:type operation: int
:return: downsampled data
:rtype: 1d numpy array
"""
if not isinstance (period, int):
raise BrainFlowError ('wrong type for period', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (operation, int):
raise BrainFlowError ('wrong type for operation', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if period <= 0:
raise BrainFlowError ('Invalid value for period', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
downsampled_data = numpy.zeros (int (data.shape[0] / period)).astype (numpy.float64)
res = DataHandlerDLL.get_instance ().perform_downsampling (data, data.shape[0], period, operation, downsampled_data)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to perform downsampling', res)
return downsampled_data
:type data: 1d numpy array
:param sampling_rate: board's sampling rate
:type sampling_rate: float
:param cutoff: cutoff frequency
:type cutoff: float
:param order: filter order
:type order: int
:param filter_type: filter type from special enum
:type filter_type: int
:param ripple: ripple value for Chebyshev filter
:type ripple: float
"""
if not isinstance (sampling_rate, int):
raise BrainFlowError ('wrong type for sampling rate', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (filter_type, int):
raise BrainFlowError ('wrong type for filter type', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
res = DataHandlerDLL.get_instance ().perform_highpass (data, data.shape[0], sampling_rate, cutoff, order, filter_type, ripple)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to apply high pass filter', res)
:type wavelet: str
:param decomposition_level: level of decomposition
:type decomposition_level: int
:return: tuple of wavelet coeffs in format [A(J) D(J) D(J-1) ..... D(1)] where J is decomposition level, A - app coeffs, D - detailed coeffs, and array with lengths for each block
:rtype: tuple
"""
try:
wavelet_func = wavelet.encode ()
except:
wavelet_func = wavelet
wavelet_coeffs = numpy.zeros (data.shape[0] + 2 * (40 + 1)).astype (numpy.float64)
lengths = numpy.zeros (decomposition_level + 1).astype (numpy.int32)
res = DataHandlerDLL.get_instance ().perform_wavelet_transform (data, data.shape[0], wavelet_func, decomposition_level, wavelet_coeffs, lengths)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to perform wavelet transform', res)
# we could return a tuple here but lets keep it like in other bindings
return wavelet_coeffs[0: sum (lengths)], lengths
:type data: 1d numpy array
:param sampling_rate: board's sampling rate
:type sampling_rate: float
:param cutoff: cutoff frequency
:type cutoff: float
:param order: filter order
:type order: int
:param filter_type: filter type from special enum
:type filter_type: int
:param ripple: ripple value for Chebyshev filter
:type ripple: float
"""
if not isinstance (sampling_rate, int):
raise BrainFlowError ('wrong type for sampling rate', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (filter_type, int):
raise BrainFlowError ('wrong type for filter type', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
res = DataHandlerDLL.get_instance ().perform_lowpass (data, data.shape[0], sampling_rate, cutoff, order, filter_type, ripple)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to perform low pass filter', res)
def perform_rolling_filter (cls, data, period, operation):
"""smooth data using moving average or median
:param data: data to smooth, it works in-place
:type data: 1d numpy array
:param period: window size
:type period: int
:param operation: int value from AggOperation enum
:type operation: int
"""
if not isinstance (period, int):
raise BrainFlowError ('wrong type for period', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (operation, int):
raise BrainFlowError ('wrong type for operation', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
res = DataHandlerDLL.get_instance ().perform_rolling_filter (data, data.shape[0], period, operation)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to smooth data', res)
:param order: filter order
:type order: int
:param filter_type: filter type from special enum
:type filter_type: int
:param ripple: ripple value for Chebyshev filter
:type ripple: float
"""
if not isinstance (sampling_rate, int):
raise BrainFlowError ('wrong type for sampling rate', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (filter_type, int):
raise BrainFlowError ('wrong type for filter type', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
res = DataHandlerDLL.get_instance ().perform_bandpass (data, data.shape[0], sampling_rate, center_freq, band_width, order, filter_type, ripple)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to apply band pass filter', res)
:type data: 1d numpy array
:param sampling_rate: board's sampling rate
:type sampling_rate: float
:param center_freq: center frequency
:type center_freq: float
:param band_width: band width
:type band_width: float
:param order: filter order
:type order: int
:param filter_type: filter type from special enum
:type filter_type: int
:param ripple: ripple value for Chebyshev filter
:type ripple: float
"""
if not isinstance (sampling_rate, int):
raise BrainFlowError ('wrong type for sampling rate', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (filter_type, int):
raise BrainFlowError ('wrong type for filter type', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
res = DataHandlerDLL.get_instance ().perform_bandstop (data, data.shape[0], sampling_rate, center_freq, band_width, order, filter_type, ripple)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to apply band stop filter', res)
:type data: 1d numpy array
:param sampling_rate: board's sampling rate
:type sampling_rate: float
:param center_freq: center frequency
:type center_freq: float
:param band_width: band width
:type band_width: float
:param order: filter order
:type order: int
:param filter_type: filter type from special enum
:type filter_type: int
:param ripple: ripple value for Chebyshev filter
:type ripple: float
"""
if not isinstance (sampling_rate, int):
raise BrainFlowError ('wrong type for sampling rate', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if not isinstance (filter_type, int):
raise BrainFlowError ('wrong type for filter type', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
if len (data.shape) != 1:
raise BrainFlowError ('wrong shape for filter data array, it should be 1d array', BrainflowExitCodes.INVALID_ARGUMENTS_ERROR.value)
res = DataHandlerDLL.get_instance ().perform_bandpass (data, data.shape[0], sampling_rate, center_freq, band_width, order, filter_type, ripple)
if res != BrainflowExitCodes.STATUS_OK.value:
raise BrainFlowError ('unable to apply band pass filter', res)