biosiglive.processing package

Submodules

biosiglive.processing.compute_mvc module

This file is part of biosiglive. it is an example to see how to use biosiglive to compute the maximal voluntary

contraction from EMG signals.

class biosiglive.processing.compute_mvc.ComputeMvc(interface_type: str | InterfaceType = InterfaceType.PytrignoClient, interface_ip: str = '127.0.0.1', interface_port: int = 801, output_file: str = None, muscle_names: list = None, emg_frequency: float = 2000, acquisition_rate: int = 100, mvc_windows: int = 2000, range_muscle: tuple | int = None, custom_interface: GenericInterface = None)[source]

Bases: object

run(show_data: bool = False) list[source]

Run the MVC program.

Parameters:

show_data (bool) – If True, the data will be displayed in live in a separate plot.

Returns:

The list of the MVC value for each muscle.

Return type:

list

set_processing_method(moving_average: bool = True, low_pass: bool = False, custom: bool = False, custom_function: callable = None, bandpass_frequency: tuple = (10, 425), lowpass_frequency: float = 5, lowpass_order: int = 4, butterworth_order: int = 4, ma_window: int = 200)[source]

Set the emg processing method. This method allow to customize the processing of the emg signal, so it need to be called before the start of the acquisition.

Parameters:
  • moving_average (bool) – If True, the emg data will be processed with a moving average.

  • low_pass (bool) – If True, the emg data will be processed with a low pass filter.

  • custom (bool) – If True, the emg data will be processed with a custom function.

  • custom_function (callable) – The custom function. Input : raw data, device frequency Output : processed data.

  • bandpass_frequency (tuple) – The frequency of the bandpass filter.

  • lowpass_frequency (float) – The frequency of the low pass filter.

  • lowpass_order (int) – The order of the low pass filter.

  • butterworth_order (int) – The order of the butterworth filter.

  • ma_window (int) – The size of the moving average window.

biosiglive.processing.data_processing module

This file contains the functions for data processing (offline and in real-time). Both class herites

from the GenericProcessing class.

class biosiglive.processing.data_processing.GenericProcessing[source]

Bases: object

butter_lowpass_filter(data: ndarray, lowcut: float, fs: float, order: int = 4) ndarray[source]

Apply a butter lowpass filter.

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • lowcut (float) – Low cut frequency.

  • fs (float) – Sampling frequency.

  • order (int) – Order of the filter.

Returns:

Filtered data.

Return type:

numpy.ndarray

calibration_matrix(data: ndarray, matrix: ndarray) ndarray[source]

Apply a calibration matrix to the data.

Parameters:
  • data (numpy.ndarray) – Data to calibrate.

  • matrix (numpy.ndarray) – Calibration matrix.

Returns:

Calibrated data.

Return type:

numpy.ndarray

static center(emg_data: ndarray, center_value: float = None) ndarray[source]

Center the EMG data.

Parameters:
  • emg_data (numpy.ndarray) – EMG data.

  • center_value (int) – Value to center the data.

Returns:

Centered EMG data.

Return type:

numpy.ndarray

static normalize_emg(emg_data: ndarray, mvc_list: list) ndarray[source]

Normalize EMG data.

Parameters:
  • emg_data (numpy.ndarray) – EMG data.

  • mvc_list (list) – List of MVC values.

Returns:

Normalized EMG data.

Return type:

numpy.ndarray

process_generic_signal(data: ndarray, norm_values: list | tuple = None, band_pass_filter=True, low_pass_filter=False, moving_average=True, centering=True, absolute_value=True, normalization=False, moving_average_window=200, **kwargs) ndarray[source]

Process EMG data.

Parameters:
  • data (numpy.ndarray) – EMG data.

  • norm_values (list) – Values to normalize the signal.

  • band_pass_filter (bool) – Apply band pass filter.

  • low_pass_filter (bool) – Apply low pass filter.

  • moving_average (bool) – Apply moving average.

  • centering (bool) – Apply centering.

  • absolute_value (bool) – Apply absolute value.

  • normalization (bool) – Apply normalization.

  • moving_average_window (int) – Moving average window.

Returns:

Processed EMG data.

Return type:

numpy.ndarray

update_signal_processing_parameters(**kwargs)[source]

update the signal processing parameters.

Parameters:

kwargs (dict) – Dictionary of parameters.

class biosiglive.processing.data_processing.OfflineProcessing(data_rate: float = None, processing_window: int = None)[source]

Bases: GenericProcessing

static compute_mvc(nb_muscles: int, mvc_trials: ndarray, window_size: int, tmp_file: str = None, output_file: str = None, save_file: bool = False) list[source]

Compute MVC from several mvc_trials.

Parameters:
  • nb_muscles (int) – Number of muscles.

  • mvc_trials (numpy.ndarray) – EMG data for all trials.

  • window_size (int) – Size of the window to compute MVC. Usually it is 1 second so the data rate.

  • tmp_file (str) – Name of the temporary file.

  • output_file (str) – Name of the output file.

  • save_file (bool) – If true, save the results.

Returns:

MVC for each muscle.

Return type:

list

process_emg(data: ndarray, mvc_list: list = None, **kwargs) ndarray[source]

Process EMG data.

Parameters:
  • data (np.ndarray) – Raw EMG data.

  • mvc_list (list) – List of MVC for each muscle.

Returns:

Processed EMG data.

Return type:

np.ndarray

class biosiglive.processing.data_processing.RealTimeProcessing(data_rate: int | float, processing_window: int = None)[source]

Bases: GenericProcessing

custom_processing(funct: callable, data_tmp: ndarray, **kwargs) ndarray[source]

Allow to apply a custom processing function to the data.

Parameters:
  • funct (callable) – Function to apply to the data.

  • data_tmp (numpy.ndarray) – Data to process.

Returns:

Processed data.

Return type:

numpy.ndarray

get_mean_process_time()[source]
get_peaks(new_sample: ndarray, threshold: float, min_peaks_interval=None) tuple[source]

Allow to get the number of peaks for an analog signal (to get cadence from treadmill for instance).

Parameters:
  • new_sample (numpy.ndarray) – New sample to add to the signal.

  • threshold (float) – Threshold to detect peaks.

  • min_peaks_interval (float) – Minimum interval between two peaks.

Returns:

Number of peaks and the processed signal.

Return type:

tuple

process_emg(emg_data: ndarray, mvc_list: list | tuple = None, band_pass_filter=True, low_pass_filter=False, moving_average=True, centering=True, absolute_value=True, normalization=False, moving_average_window=200, **kwargs) ndarray[source]

Process EMG data in real-time.

Parameters:
  • emg_data (numpy.ndarray) – Temporary EMG data (nb_emg, emg_sample).

  • mvc_list (list) – MVC values.

  • band_pass_filter (bool) – True if apply band pass filter.

  • low_pass_filter (bool) – True if apply low pass filter.

  • moving_average (bool) – True if apply moving average.

  • centering (bool) – True if apply centering.

  • absolute_value (bool) – True if apply absolute value.

  • normalization (bool) – True if apply normalization.

  • moving_average_window (int) – Moving average window.

Returns:

processed EMG data.

Return type:

np.ndarray

process_imu(im_data: ndarray, accel: bool = False, squared: bool = False, norm_min_bound: int = None, norm_max_bound: int = None, **kwargs) ndarray[source]

Process IMU data in real-time.

Parameters:
  • im_data (numpy.ndarray) – Temporary IMU data (nb_imu, im_sample).

  • accel (bool) – True if current data is acceleration data to adapt the processing.

  • squared (bool) – True if apply squared.

  • norm_min_bound (int) – Normalization minimum bound.

  • norm_max_bound (int) – Normalization maximum bound.

Returns:

processed IMU data.

Return type:

np.ndarray

biosiglive.processing.msk_functions module

This file contains biorbd specific functions for musculoskeletal analysis such as inverse or direct kinematics.

class biosiglive.processing.msk_functions.MskFunctions(model: str, data_buffer_size: int = 1)[source]

Bases: object

compute_direct_kinematics(states: ndarray) ndarray[source]

Compute the direct kinematics using the joint angle and a biorbd model type.

Parameters:

states (np.ndarray) – The states to compute the direct kinematics.

Returns:

The markers.

Return type:

np.ndarray

compute_inverse_kinematics(markers: ndarray, method: InverseKinematicsMethods | str = InverseKinematicsMethods.BiorbdLeastSquare, kalman_freq: int | float = 100, kalman: callable = None, custom_function: callable = None, **kwargs) tuple[source]

Function to apply the inverse kinematics using the markers data and a biorbd model type.

Parameters:
  • markers (numpy.array) – The experimental markers.

  • kalman (biorbd.KalmanReconsMarkers) – The Kalman filter to use.

  • kalman_freq (int) – The frequency of the Kalman filter.

  • method (Union[InverseKinematicsMethods, str]) – The method to use to compute the inverse kinematics.

  • custom_function (callable) – Custom function to use.

Returns:

The joint angle and velocity.

Return type:

tuple

get_mean_process_time()[source]

Get the mean process time.

Returns:

The mean process time.

Return type:

float

Module contents