respyra.core.target_generator¶
Target waveform generator for respiratory tracking.
Generates sinusoidal breathing-target waveforms from a sequence of frequency/cycle segments. After a baseline calibration phase the generator maps target values into the participant’s actual force range so the target dot stays within their comfortable breathing amplitude.
Usage¶
- from respyra.core.target_generator import (
SegmentDef, ConditionDef, TargetGenerator, calibrate_from_baseline,
)
center, amplitude = calibrate_from_baseline(baseline_forces) condition = ConditionDef(‘slow_steady’, [SegmentDef(0.1, 3)]) gen = TargetGenerator(condition, center, amplitude)
target_force = gen.get_target(t) # call each frame with tracking time
- class respyra.core.target_generator.SegmentDef(freq_hz, n_cycles)[source]¶
Bases:
objectOne constant-frequency segment of a breathing-target pattern.
- Parameters:
- class respyra.core.target_generator.ConditionDef(name, segments=<factory>, feedback_gain=1.0)[source]¶
Bases:
objectA named experimental condition composed of one or more segments.
- Parameters:
name (str) – Human-readable label used in data files (e.g.
'slow_steady').segments (list[SegmentDef]) – Ordered list of segments that form the repeating pattern.
feedback_gain (float) – Multiplicative gain applied to the visual trace around the participant’s breathing center.
1.0= veridical feedback. Values > 1 amplify displayed deviations; < 1 attenuate them.
- segments: list[SegmentDef]¶
- respyra.core.target_generator.calibrate_from_baseline(force_samples, min_amplitude=0.5)[source]¶
Derive target center and amplitude from baseline breathing data.
- Parameters:
- Return type:
- Returns:
center (float) – Midpoint of the participant’s breathing range, used as the DC offset for the sinusoidal target.
amplitude (float) – Half-amplitude of the sinusoidal target, clamped to at least min_amplitude.
- class respyra.core.target_generator.TargetGenerator(condition, center, amplitude)[source]¶
Bases:
objectReal-time sinusoidal breathing-target generator.
Call
get_target()each frame with the current tracking time to obtain the target force value for the respiratory tracking dot.The waveform is
center + amplitude * sin(2 * pi * freq * t_local)where t_local is the time within the currently active segment. Multi-segment patterns loop seamlessly because each segment uses an integer number of cycles (phase-continuous boundaries).- Parameters:
condition (ConditionDef) – Defines the segment sequence.
center (float) – DC offset (Newtons), typically from
calibrate_from_baseline().amplitude (float) – Half-amplitude (Newtons) of the sinusoidal target.