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

greedy

src

greedy is a combinatorial optimization that greedily selects the phase of each transducer one at a time from a set of discrete candidates. The algorithm is based on the paper by Suzuki et al. (Suzuki et al., 2021).

greedy optimizes only the phases, not the intensities. You give the intensities in intensities, and greedy chooses the phases for those intensities. intensities takes either a uniform value for all transducers (Intensity) or a per-transducer buffer. A transducer whose intensity is 0 is left out of the search and gets phase 0.

You must give the order in which the transducers are visited in order. The indices run through the whole geometry (from 0 to geometry.num_transducers() - 1 in device order), and order should contain every transducer exactly once. Visiting the transducers in random order is recommended, so you normally pass a sequence shuffled with random numbers.

greedy(
&geometry,
&foci,
wavelength,
&intensities,
&order,
&option,
&mut dst,
)?;
Parameter Type Description
geometry &Geometry Device layout
foci &[AmplitudeTarget] Sequence of focal points (position and target amplitude)
wavelength Length Wavelength
intensities impl Into<PatternIntensity> Intensity (a uniform Intensity, or a per-device &[Vec<Intensity>] buffer)
order &[usize] Order in which the transducers are visited (a sequence of indices)
option &GreedyOption Additional options (see below)
dst &mut [Vec<Phase>] Phase output buffer
GreedyOption {
phase_quantization_levels,
directivity,
objective_func,
}
Field Type Default
phase_quantization_levels NonZeroU8 16
directivity Directivity Sphere
objective_func fn(Complex<f32>, Amplitude) -> f32 abs_objective_func
  • phase_quantization_levels — the number of divisions of the phase candidates. The larger it is, the higher the phase resolution.
  • objective_func — the objective function that evaluates each candidate. The default abs_objective_func returns the absolute value of the difference between the magnitude of the synthesized sound pressure and the target amplitude.
    • Configurable only in the Rust version. In other languages, the default objective function is used.
use std::num::NonZeroU8;
use rand::seq::SliceRandom;
use autd3_rs::geometry::{Autd3, Geometry, offset};
use autd3_rs::units::{m, mm, s};
use autd3_rs::value::Intensity;
use autd3_rs_pattern::wavelength;
use autd3_rs_pattern_holo::{
AmplitudeTarget, Directivity, GreedyOption, Pa, abs_objective_func, greedy,
};
let geometry = Geometry::new(vec![Autd3::default()]);
let mut order: Vec<usize> = (0..geometry.num_transducers()).collect();
order.shuffle(&mut rand::rng());
let mut phases = geometry.phase_buffer();
greedy(
&geometry,
&[
AmplitudeTarget {
point: geometry.center() + offset(-30.0 * mm, 0.0 * mm, 150.0 * mm),
amplitude: 2.5e3 * Pa,
},
AmplitudeTarget {
point: geometry.center() + offset(30.0 * mm, 0.0 * mm, 150.0 * mm),
amplitude: 2.5e3 * Pa,
},
],
wavelength(340.0 * m / s),
Intensity::MAX,
&order,
&GreedyOption {
phase_quantization_levels: NonZeroU8::new(16).unwrap(),
directivity: Directivity::Sphere,
objective_func: abs_objective_func,
},
&mut phases,
)?;