Skip to content

Rate Detection

eitprocessing.features.rate_detection.RateDetection dataclass

RateDetection(
    subject_type: Literal["adult", "neonate"],
    *,
    welch_window: float = 30.0,
    welch_overlap: float = 0.5,
    min_heart_rate: float | None = None,
    max_heart_rate: float | None = None,
    min_respiratory_rate: float | None = None,
    max_respiratory_rate: float | None = None,
    refine_estimated_frequency: bool = True
)

Detect the respiratory and heart rate from EIT pixel data.

This algorithm attempts to detect the respiratory and heart rate from EIT pixel data. It is based on the observation that many high-amplitude pixels have the respiratory rate as the main frequency, while in low-amplitude pixels the power of the heart rate is relatively high. The algorithm uses Welch's method to estimate the power spectrum of the summed pixel data and individual pixels. It then identifies the respiratory rate as the frequency with the highest power for the summed pixels within the specified range. The power spectra of the individual pixels are normalized and averaged. The normalized power spectrum of the summed pixels is subtracted from the average of the normalized individual power spectra. The frequency with the highest relative power in this difference within the specified range is taken as the heart rate.

If either rate is variable, the algorithm will in most cases return an average frequency. If there are multiple distinct frequencies, e.g., due to a change in the controlled respiratory rate, multiple peaks might be visible in the power spectrum. The algorithm will only return the frequency with the highest power in the specified range.

The algorithm can't distinguish between the respiratory and heart rate if they are too close together, especially in very short signals (or when the Welch window is short). The algorithm can distinguish between both rates if the heart rate is at one of the harmonics of the respiratory rate.

If the refine_estimated_frequency attribute is set to False, the estimated frequency is simply the location of the peak of the power Welch spectrum. Since Welch's method results in a limited number of frequency bins, this can lead to inaccuracies, especially with short or low-sample frequency data. If refine_estimated_frequency is set to True (default), the estimated frequency is refined using parabolic interpolation, which often yields more accurate results, even with short signals, low signal-to-noise ratio and very similar (but distinct) respiratory and heart rates. See e.g. Quadratic Interpolation of Spectral Peaks.

The respiratory and heart rate limits can be set when initializing this algorithm. Default values for adults and neonates are set in DEFAULT_RATE_LIMITS.

Although the algorithm might perform reasonably on data as short as 10 seconds (200 samples), it is recommended to use at least 30 seconds of data for reliable results. Longer data wil yield more reliable results, but only if the respiratory and heart rates are stable.

Note that the algorithm performs best if no large changes in end-expiratory impedance occur in the data, the data is unfiltered, and the respiratory and heart rates are relatively stable.

ATTRIBUTE DESCRIPTION
subject_type

The type of subject, either "adult" or "neonate". This affects the default settings for the minimum and maximum heart and respiratory rates.

TYPE: Literal['adult', 'neonate']

welch_window

The length of the Welch window in seconds.

TYPE: float

welch_overlap

The fraction overlap between Welch windows (e.g., 0.5 = 50% overlap).

TYPE: float

min_heart_rate

The minimum heart rate in Hz. If None, the default value for the subject type is used.

TYPE: float

max_heart_rate

The maximum heart rate in Hz. If None, the default value for the subject type is used.

TYPE: float

min_respiratory_rate

The minimum respiratory rate in Hz. If None, the default value for the subject type is used.

TYPE: float

max_respiratory_rate

The maximum respiratory rate in Hz. If None, the default value for the subject type is used.

TYPE: float

refine_estimated_frequency

If True, the estimated frequency is refined using parabolic interpolation. If False, the frequency with the highest power is used as the estimated frequency.

TYPE: bool

plotting property

A utility class for plotting the the results of the RateDetection algorithm.

The plotting.plot(**captures) method can be used to plot the results of the algorithm. It takes the captured variables from the apply method as keyword arguments.

Example:

>>> rd = RateDetection("adult")
>>> captures = {}
>>> estimated_respiratory_rate, estimated_heart_rate = rd.detect_respiratory_heart_rate(eit_data, captures)
>>> fig = rd.plotting(**captures)
>>> fig.savefig(...)

apply

apply(
    eit_data: EITData,
    *,
    captures: dict | None = None,
    suppress_length_warnings: bool = False,
    suppress_edge_case_warning: bool = False
) -> tuple[float, float]

Detect respiratory and heart rate based on pixel data.

NB: the respiratory and heart rate are returned in Hz. Multiply by 60 to convert to breaths/beats per minute.

PARAMETER DESCRIPTION
eit_data

EITData object containing pixel impedance data and sample frequency.

TYPE: EITData

captures

Optional dictionary to capture additional information during processing. Can be used for plotting or debugging purposes.

TYPE: dict | None DEFAULT: None

suppress_length_warnings

If True, suppress warnings about segment length being larger than the data length or overlap being larger than segment length. Defaults to False.

TYPE: bool DEFAULT: False

suppress_edge_case_warning

If True, suppress warnings about the maximum power being at the edge of the frequency range, which prevents frequency refinement. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
tuple[float, float]

A tuple containing the estimated respiratory rate and heart rate in Hz.