gradient_sound

Contents

gradient_sound#

pypulseqpp.gradient_sound()[source]#

Return the stereo audio of the gradient waveforms of the three axes.

Parameters:
  • waveforms (sequence of array_like) – Three (2, n) arrays of time (s) over gradient amplitude (Hz/m), for the x, y and z axes, as Sequence.waveforms() returns them. The amplitude is linear between an axis’s corners and zero outside them; an axis may be empty.

  • num_samples (int) – Number of audio samples.

  • first_sample (int, default=0) – Index of the first sample. Sample k is at k / sample_rate s on the waveforms’ time axis.

  • channel_weights (sequence of float, default=(1.0, 1.0, 1.0)) – Weights of the x, y and z axes.

  • sample_rate (float, default=44100) – Audio sample rate in Hz.

  • peak (float, default=None) – Magnitude (Hz/m) of the filtered signal that is scaled to 0.95. By default the largest magnitude among the samples returned.

Returns:

(2, num_samples). The first channel carries the x axis and the second the y axis, each weighted, and both carry half the weighted z axis. Both are smoothed with MATLAB’s gausswin window of 2 * round(sample_rate / 6000) + 1 samples, normalised to unit sum, and scaled by 0.95 / peak. Samples beyond peak are not clipped, and a signal that is zero throughout is returned as zeros.

Return type:

NDArray[np.float64]

Raises:

ValueError – If waveforms does not hold three axes, channel_weights three weights, num_samples is negative, or sample_rate or peak is not positive.

Notes

The window is applied to the waveforms beyond the samples returned, up to round(sample_rate / 6000) samples either side. Calls over consecutive sample ranges with one peak therefore return the samples of one call over their union, provided each call’s waveforms cover its range widened by that margin.

Examples

>>> import numpy as np
>>> import pypulseqpp as pp
>>> gx = np.array([[0.0, 1e-3, 2e-3, 3e-3], [0.0, 1e5, 1e5, 0.0]])
>>> empty = np.zeros((2, 0))
>>> audio = pp.gradient_sound([gx, empty, empty], 133)
>>> audio.shape
(2, 133)
>>> float(np.abs(audio).max()), float(np.abs(audio[1]).max())
(0.95, 0.0)