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.
Custom Pattern
Section titled “Custom Pattern”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);emissions = geometry.pattern_buffer()for slot, device in zip(emissions, geometry): for t, pos in enumerate(device.positions()): dist = float(np.linalg.norm(target - pos)) slot[t] = Emission( Phase(-dist / wavelength * 2.0 * math.pi * rad), Intensity.MAX, )
Pattern(emissions)var emissions = geometry.PatternBuffer();foreach (var device in geometry){ var slot = emissions[device.Idx]; for (var t = 0; t < device.NumTransducers; t++) { var dist = Vector3.Distance(target, device.Position(t)); slot[t] = new Emission( (Phase)(-dist / wavelength.Mm * 2.0f * MathF.PI * rad), Intensity.Max); }}
new Pattern(emissions);Custom Modulation
Section titled “Custom Modulation”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);length = 10buffer = ModulationBuffer(length)buffer[0] = 0xFF
Modulation(SamplingConfig.FREQ_4K, buffer)var length = 10;var buffer = new ModulationBuffer(length);buffer[0] = 0xFF;
new Modulation(SamplingConfig.Freq4k, buffer);