Skip to content
This is the development version of the documentation. It may change before the next release. See 0.9.x for the latest release.

Custom Patterns and Modulation

Pattern and Modulation are commands that send an already-computed buffer directly to the device. The compute helpers are pre-provided compute helpers. By building the buffer directly without going through a helper, arbitrary patterns and modulation can be expressed.

A pattern is a pair of a phase buffer, which lays out a Vec<Phase> for each device, and an intensity. Geometry::phase_buffer allocates the phase buffer for all devices, and the phase of each transducer can be freely set. For the intensity, pass an Intensity directly when it is the same for every transducer, and allocate a buffer with Geometry::intensity_buffer only when it has to differ per transducer.

The following is an example of manually computing the same single focal point as focus, without using a helper. It gives each transducer a phase according to the distance from the transducer to the focal point.

let mut phases = geometry.phase_buffer();
for (slot, device) in phases.iter_mut().zip(&geometry) {
for (p, &pos) in slot.iter_mut().zip(device.positions()) {
let dist = (target - pos).norm();
*p = Phase::from(-dist / wavelength.mm() * 2.0 * PI * rad);
}
}
Pattern::new(&phases, Intensity::MAX);

Modulation is a pair of a &[u8] buffer representing the AM waveform and a SamplingConfig. Each element of the buffer represents the amplitude of one sample.

The following is an example of Burst modulation that outputs only the first sample within a period.

let length = 10;
let mut data = vec![0x00u8; length];
data[0] = 0xFF;
Modulation::new(SamplingConfig::FREQ_4K, &data);