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.

SamplingConfig

SamplingConfig represents the sampling frequency of Modulation or STM. The sampling frequency must be the ultrasound frequency (40 kHz) divided by an integer.

SamplingConfig::new(NonZeroU16::new(10).unwrap());
SamplingConfig::from_freq(4. * kHz)?;
SamplingConfig::from_period(Duration::from_micros(250))?;

All of the above represent 4 kHz (division ratio 10) and are equivalent to one another.

SamplingConfig is ultimately converted to a division ratio (u16).

The relationship between the division ratio , the sampling frequency , and the sampling period is as follows.

When specified by frequency or period, it is an error if it does not evenly divide 40 kHz (i.e., does not yield an integer division ratio).

Frequently used constants are provided in advance.

Constant Sampling frequency Division ratio
FREQ_40K 40 kHz 1
FREQ_4K 4 kHz 10