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.

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::new(4. * kHz);
SamplingConfig::new(Duration::from_micros(250));
SamplingConfig::new(Nearest(4. * kHz));
SamplingConfig::new(Nearest(Duration::from_micros(250)));

SamplingConfig::new accepts NonZeroU16 / Freq<f32> / Duration / Nearest<Freq<f32>> / Nearest<Duration>. All of the above represent 4 kHz (division ratio 10) and are equivalent to one another.

SamplingConfig can be specified as one of the following. Internally, it is ultimately converted to a division ratio (u16).

Specification method Type
Division ratio NonZeroU16
Frequency Freq<f32>
Period Duration

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). To round an indivisible value to the nearest division ratio, wrap the frequency/period in Nearest.

Frequently used constants are provided in advance.

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