Skip to content

sine

src

sine generates a sine-wave amplitude modulation.

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

The value of each sample is given by the following equation, for amplitude (amplitude), offset (offset), and phase (phase).

freq is specified as a Freq (150 * Hz or 150.0 * Hz). 150 * Hz and 150.0 * Hz represent the same frequency.

SineOption {
amplitude,
offset,
phase,
clamp,
..Default::default()
}
Field Type Default Description
amplitude u8 0xFF amplitude of the sine wave
offset u8 0x80 DC offset
phase Angle Angle::ZERO phase
clamp bool false whether to clamp out-of-range values to [0, 255]

If the combination of amplitude and offset causes the waveform to fall outside the [0, 255] range, an error occurs when clamp is false. Choose values that stay within range, or set clamp to true.

Due to the constraints of SamplingConfig, the specified frequency may not be a representable frequency. freq must be a frequency that fits an integer number of samples in a period; otherwise an error is returned.

use autd3_rs::units::{Hz, rad};
use autd3_rs::value::SamplingConfig;
use autd3_rs_modulation::{SineOption, modulation_buffer, sine};
let mut dst = modulation_buffer();
sine(
150 * Hz,
&SineOption {
amplitude: 0xFF,
offset: 0x80,
phase: 0.0 * rad,
clamp: false,
..Default::default()
},
SamplingConfig::FREQ_4K,
&mut dst,
)?;