Skip to content
This is the development version of the documentation. It may change before the next release. See 0.6.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 buffer that lays out a Vec<Emission> for each device. Geometry::pattern_buffer allocates the buffer for all devices, and the Emission (phase and intensity) of each transducer can be freely set.

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 emissions = geometry.pattern_buffer();
for (slot, device) in emissions.iter_mut().zip(&geometry) {
for (e, &pos) in slot.iter_mut().zip(device.positions()) {
let dist = (target - pos).norm();
*e = Emission {
phase: Phase::from(-dist / wavelength.mm() * 2.0 * PI * rad),
intensity: Intensity::MAX,
};
}
}
Pattern::new(&emissions);

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);