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, sampling_config, &mut dst)?;square(freq, option, sampling_config, dst)Modulation.Square(freq, option, samplingConfig, 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
Section titled “SquareOption”SquareOption { low, high, duty, ..Default::default()}SquareOption( low, high, duty,)new SquareOption{ Low = low, High = high, Duty = duty,}| 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.
Example
Section titled “Example”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,)?;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, ), 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.Freq4k, dst);