Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix compute_time_to_peak function to use correct axis for demodulation
  • Loading branch information
wesselvannierop committed Oct 16, 2026
commit 3cf820af26226a1b96e8092c75beaa1aa6fc3a40
9 changes: 9 additions & 0 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from zea.func.ultrasound import (
channels_to_complex,
complex_to_channels,
compute_time_to_peak,
compute_time_to_peak_stack,
construct_acquisition_from_synthetic_aperture,
decode_hadamard,
Expand Down Expand Up @@ -977,6 +978,14 @@ def test_compute_time_to_peak():

assert np.allclose(t_peak, 1e-6, atol=1e-8), f"t_peak should be close to 1e-6, got {t_peak}"

# With a sine carrier the largest raw sample sits a quarter period away from the
# envelope peak, so this catches taking argmax(|waveform|) instead of the envelope.
waveform_sin = np.exp(-((t - 1e-6) ** 2) / (2 * (0.2e-6) ** 2)) * np.sin(
2 * np.pi * center_frequency0 * (t - 1e-6)
)
t_peak = compute_time_to_peak(waveform_sin, center_frequency0, 250e6)
assert np.allclose(t_peak, 1e-6, atol=1e-8), f"t_peak should be close to 1e-6, got {t_peak}"


# Only the beamformers zea.ops defines itself. A model-backed beamformer (such as
# "able", registered by zea.models.able) is not comparable across backends: its
Expand Down
2 changes: 1 addition & 1 deletion zea/func/ultrasound.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def compute_time_to_peak(waveform, center_frequency, waveform_sampling_frequency
raise ValueError("Waveform has zero samples.")

waveforms_iq_complex_channels = demodulate(
waveform[..., None], center_frequency, waveform_sampling_frequency, axis=-1
waveform[..., None], center_frequency, waveform_sampling_frequency, axis=-2
)
waveforms_iq_complex = ops.view_as_complex(waveforms_iq_complex_channels)
envelope = ops.abs(waveforms_iq_complex)
Expand Down