Utilities

This section shows general objects and helper functions that are used with this package.

Custom Waveform

You can define custom waveforms by using the balderhub.waveform.lib.utils.CustomNonPeriodicWaveform and balderhub.waveform.lib.utils.CustomPeriodicWaveform objects.

class balderhub.waveform.lib.utils.waveforms.CustomNonPeriodicWaveform(data: ndarray, multiplier_amplitude_volt: float, delta_time_sec: float, offset_vdc: float = 0)

Bases: BaseNonPeriodicWaveform

Custom individual NON-PERIODOC waveform that expects its data in the constructor

property data: ndarray

needs to return a list with values between 0 and 1

class balderhub.waveform.lib.utils.waveforms.CustomPeriodicWaveform(data: ndarray, frequency_hz: float, amplitude_vpp: float, offset_vdc: float = 0, phase: float = 0)

Bases: BasePeriodicWaveform

Custom individual PERIODOC waveform that expects its data in the constructor

property data: ndarray

needs to return a list with values between 0 and 1

Common Waveform Classes

class balderhub.waveform.lib.utils.waveforms.common.CardiacWaveform(frequency_hz: float, amplitude_vpp: float, offset_vdc: float = 0, phase: float = 0)

Bases: BasePeriodicWaveform

simple cardiac waveform

property data: ndarray

needs to return a list with values between 0 and 1

property points_per_period: int
Returns:

returns the number of points the raw-data should have

class balderhub.waveform.lib.utils.waveforms.common.CosineWaveform(frequency_hz: float, amplitude_vpp: float, offset_vdc: float = 0, phase: float = 0)

Bases: BasePeriodicWaveform

simple cosine waveform

property data: ndarray

needs to return a list with values between 0 and 1

property points_per_period: int
Returns:

returns the number of points the raw-data should have

class balderhub.waveform.lib.utils.waveforms.common.SineWaveform(frequency_hz: float, amplitude_vpp: float, offset_vdc: float = 0, phase: float = 0)

Bases: BasePeriodicWaveform

simple sine waveform

property data: ndarray

needs to return a list with values between 0 and 1

property points_per_period: int
Returns:

returns the number of points the raw-data should have

class balderhub.waveform.lib.utils.waveforms.common.DCWaveform(frequency_hz: float, amplitude_vpp: float, offset_vdc: float = 0, phase: float = 0)

Bases: BasePeriodicWaveform

simple DC Waveform

property data: ndarray

needs to return a list with values between 0 and 1

Base Classes

class balderhub.waveform.lib.utils.waveforms.AbstractWaveform

Bases: ABC

Abstract base class describing a waveform

abstract compare(with_waveform: AbstractWaveform, max_allowed_rmse: float = 0.01) bool

This method compares to waveforms with each other. If one of this waveforms is a PERIODIC and the other one is a NON-PERIODIC it will automatically try to convert the NON-PERIODIC waveform to a PERIODIC waveform.

Parameters:
  • with_waveform – the other waveform to compare with

  • max_allowed_rmse – maximal allowed RMSE value to classify both waveforms as identically

Returns:

True if both waveforms are identical, otherwise False

abstract property data: ndarray

needs to return a list with values between 0 and 1

abstract property delta_time_sec: float
Returns:

delta time between two data points

abstract get_data_in_volts() ndarray

This method converts the raw data according to the waveform parameters (like amplitude, phase, ..) into a numpy array that descibes the exact volt values. :return: a numpy array with voltage values

abstract get_resampled_version(interval_sec: float) AbstractWaveformTypeT

This method resamples the internal raw data to ensure that the interval_sec is the exact time between every step.

Parameters:

interval_sec – the interval between every single data point

Returns:

a new waveform instance with the resampled data points as raw data

save_plot(filepath: Path) None

This method creates a matplotlib plot and saves it at the given filepath. :param filepath: the filepath to save the plot to

show_plot() None

This method shows a matplotlib plot of the waveform.

class balderhub.waveform.lib.utils.waveforms.BaseNonPeriodicWaveform(multiplier_amplitude_volt: float, delta_time_sec: float, offset_vdc: float = 0)

Bases: AbstractWaveform, ABC

Base abstract class for describing a NON-PERIODIC waveform

compare(with_waveform: BasePeriodicWaveform | BaseNonPeriodicWaveform, max_allowed_rmse=0.01) bool

This method compares to waveforms with each other. If one of this waveforms is a PERIODIC and the other one is a NON-PERIODIC it will automatically try to convert the NON-PERIODIC waveform to a PERIODIC waveform.

Parameters:
  • with_waveform – the other waveform to compare with

  • max_allowed_rmse – maximal allowed RMSE value to classify both waveforms as identically

Returns:

True if both waveforms are identical, otherwise False

property delta_time_sec: float
Returns:

delta time between two data points

get_data_in_volts() ndarray

This method converts the raw data according to the waveform parameters (like amplitude, phase, ..) into a numpy array that descibes the exact volt values. :return: a numpy array with voltage values

get_periodic_equivalent_waveform() CustomPeriodicWaveform

This method converts the NON-PERIODIC waveform into a PERIODIC waveform. It uses correlation to determine the periodic pattern within the signal.

It raises a ValueError in case it does not detect a valid periodic pattern within the data.

Returns:

a new PERIOD waveform that describes the periodic pattern within this signal

get_resampled_version(interval_sec: float) BaseNonPeriodicWaveform

This method resamples the internal raw data to ensure that the interval_sec is the exact time between every step.

Parameters:

interval_sec – the interval between every single data point

Returns:

a new waveform instance with the resampled data points as raw data

property multiplier_amplitude_volt: float
Returns:

multiplier the raw data needs to be multiplied to define the voltage

property offset_vdc: float
Returns:

additional offset that will be added to the signal

property total_time_sec: float
Returns:

returns the total time of the signal in seconds

class balderhub.waveform.lib.utils.waveforms.BasePeriodicWaveform(frequency_hz: float, amplitude_vpp: float, offset_vdc: float = 0, phase: float = 0)

Bases: AbstractWaveform, ABC

Base abstract class for describing a PERIODIC waveform

property amplitude_vpp: float
Returns:

the amplitude value the raw data will be multiplied with

compare(with_waveform: BasePeriodicWaveform | BaseNonPeriodicWaveform, max_allowed_rmse: float = 0.01, ignore_phase: bool = False) bool

This method compares to waveforms with each other. If one of the waveforms is a PERIODIC and the other one is a NON-PERIODIC it will automatically try to convert the NON-PERIODIC waveform to a PERIODIC waveform.

If ignore_phase is True, it will ignore the position of the waveform and attempts to find the same waveform by shifting it. For example, in a cosine and sine comparison where ignore_phase=True, True would also be returned in the compare, since the signals are identical but with a phase shift of 90 degree.

Parameters:
  • with_waveform – the other waveform to compare with

  • max_allowed_rmse – maximal allowed RMSE value to classify both waveforms as identically

Returns:

True if both waveforms are identical, otherwise False

property delta_time_sec: float
Returns:

delta time between two data points

property frequency_hz: float
Returns:

the frequency that should be applied to this waveform

get_data_in_volts() ndarray

This method converts the raw data according to the waveform parameters (like amplitude, phase, ..) into a numpy array that descibes the exact volt values. :return: a numpy array with voltage values

get_phase_difference_to(other_periodic_waveform: BasePeriodicWaveform, max_allowed_rmse: float = 0.01) float | None

This method gets the phase difference between two periodic waveforms.

Parameters:

other_periodic_waveform – the other waveform

Returns:

the phase between [0,2*pi] from this waveform to the other waveform or None, if both waveforms are different

get_resampled_version(interval_sec: float) BasePeriodicWaveform

This method resamples the internal raw data to ensure that the interval_sec is the exact time between every step.

Parameters:

interval_sec – the interval between every single data point

Returns:

a new waveform instance with the resampled data points as raw data

property offset_vdc: float
Returns:

the signal offset the raw data will be added to

property phase: float
Returns:

the phase of the signal