Sequence.sound

Contents

Sequence.sound#

Sequence.sound()[source]#

Return the gradient waveforms as stereo audio, as MATLAB Pulseq’s sound does.

Parameters:
  • block_range (Sequence[int], default=None) – Two 1-based block indices; the whole sequence by default.

  • channel_weights (Sequence[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.

  • path (str or os.PathLike, default=None) – Also write the audio to this file as 16-bit PCM WAV.

Returns:

(2, n) samples, from the start of the first block played, with n = floor(duration * sample_rate) + 1 for the duration of the blocks played, scaled so that the largest magnitude is 0.95. gradient_sound() states the channels and the filter.

Return type:

NDArray[np.float64]

Raises:

ValueError – If sample_rate is not positive, or path is given and sample_rate is not an integer.

Notes

Nothing is played. The gradients are those played after each block’s rotation. With block_range, the audio lasts as long as the blocks in the range; MATLAB Pulseq’s lasts as long as the whole sequence, with silence after the range.

Examples

>>> import pypulseqpp as pp
>>> seq = pp.Sequence(pp.Opts())
>>> seq.add_block(pp.make_trapezoid("x", flat_area=1000, flat_time=3.2e-3))
1
>>> seq.sound().shape
(2, 147)