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.

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, &mut dst)?;
Parameter Type Description
freq Freq<u32> etc. modulation frequency
option &SquareOption additional options (see below)
dst &mut Vec<u8> output buffer

freq is specified in the same way as sine.

SquareOption {
low,
high,
duty,
sampling_config,
}
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
sampling_config SamplingConfig SamplingConfig::FREQ_4K sampling configuration

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

An error occurs if duty is outside the range . Setting duty to makes it always low, and setting it to makes it always high.

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