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.

square

src

square generates a square-wave amplitude modulation. It switches between the two values high and low at the specified frequency freq.

freq = 200 Hz
square(freq, &option, sampling_config, &mut dst)?;
Parameter Type Description
freq Freq etc. modulation frequency
option &SquareOption additional options (see below)
config SamplingConfig sampling configuration (see Modulation)
dst &mut Vec<u8> output buffer

freq is specified in the same way as sine.

SquareOption {
low,
high,
duty,
..Default::default()
}
Field Type Default Description
low u8 u8::MIN amplitude of the low level
high u8 u8::MAX amplitude of the high level
duty f32 0.5 fraction of the period occupied by high

Within one period, the duty fraction is high and the remainder is low.

use autd3_rs::units::Hz;
use autd3_rs::value::SamplingConfig;
use autd3_rs_modulation::{SquareOption, modulation_buffer, square};
let mut dst = modulation_buffer();
square(
150 * Hz,
&SquareOption {
low: u8::MIN,
high: u8::MAX,
duty: 0.5,
..Default::default()
},
SamplingConfig::FREQ_4K,
&mut dst,
)?;