square
srcsquare 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)?;square(freq, option, dst)Modulation.Square(freq, option, 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
Section titled “SquareOption”SquareOption { low, high, duty, sampling_config,}SquareOption( low, high, duty, sampling_config,)new SquareOption( low, high, duty, samplingConfig)| 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 duty to low, and setting it to high.
Example
Section titled “Example”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,)?;from autd3.units import Hzfrom autd3.value import SamplingConfigfrom autd3_modulation import SquareOption, modulation_buffer, square
dst = modulation_buffer()
square( 150 * Hz, SquareOption( low=0x00, high=0xFF, duty=0.5, sampling_config=SamplingConfig.FREQ_4K, ), dst,)using AUTD3;using static AUTD3.Units;
var dst = Modulation.ModulationBuffer();
Modulation.Square( 150 * Hz, new SquareOption( low: byte.MinValue, high: byte.MaxValue, duty: 0.5f, samplingConfig: SamplingConfig.Freq4k ), dst);