diff --git a/src/lib.rs b/src/lib.rs index 4161b37..dd05fcc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,6 +61,8 @@ fn lasprs(m: &Bound<'_, PyModule>) -> PyResult<()> { // Signal generator m.add_class::()?; + m.add_class::()?; + m.add_class::()?; // SLM m.add_class::()?; diff --git a/src/siggen/siggen.rs b/src/siggen/siggen.rs index 6854bdf..f7fcee3 100644 --- a/src/siggen/siggen.rs +++ b/src/siggen/siggen.rs @@ -1,7 +1,7 @@ use super::siggenchannel::SiggenChannelConfig; -use super::SiggenCommand; use super::source::{self, *}; use super::sweep::SweepType; +use super::SiggenCommand; use crate::config::*; use crate::filter::Filter; use anyhow::{bail, Result}; @@ -46,6 +46,21 @@ impl Siggen { fn newSine_py(fs: Flt, freq: Flt, nchannels: usize) -> PyResult { Ok(Siggen::newSine(fs, nchannels, freq)?) } + #[pyo3(name = "newSweep")] + #[staticmethod] + fn newSweep_py( + fs: Flt, + nchannels: usize, + fl: Flt, + fu: Flt, + sweep_time: Flt, + quiet_time: Flt, + sweep_type: SweepType, + ) -> Result { + Ok(Siggen::newSweep( + fs, nchannels, fl, fu, sweep_time, quiet_time, sweep_type, + )?) + } } impl Siggen { diff --git a/src/siggen/sweep.rs b/src/siggen/sweep.rs index 4afe5c6..ef8e310 100644 --- a/src/siggen/sweep.rs +++ b/src/siggen/sweep.rs @@ -6,6 +6,8 @@ use { const NITER_NEWTON: usize = 20; const twopi: Flt = 2. * pi; +/// Enumerator representing the type of sweep source to create. Used as +/// parameter in [Siggen::newSweep]. #[cfg_attr(feature = "python-bindings", pyclass)] #[derive(Debug, Clone)] pub enum SweepType { @@ -37,8 +39,8 @@ pub struct SweepParams { impl SweepParams { pub fn new( fs: Flt, - fl_: Flt, - fu_: Flt, + fl: Flt, + fu: Flt, sweep_time: Flt, quiet_time: Flt, sweeptype: SweepType, @@ -46,10 +48,10 @@ impl SweepParams { if fs <= 0. { bail!("Invalid sampling frequency: {} Hz", fs); } - if fl_ > fu_ { + if fl > fu { bail!("Lower frequency should be smaller than upper frequency"); } - if fu_ >= fs / 2. { + if fu >= fs / 2. { bail!("Upper frequency should be smaller than sampling frequency"); } if sweep_time <= 0. { @@ -59,10 +61,11 @@ impl SweepParams { bail!("Invalid sweep time: too short"); } + // For backward sweeps, we just reverse the start and stop frequency. let (fl, fu) = if matches!(sweeptype, SweepType::BackwardLin | SweepType::BackwardLog) { - (fu_, fl_) + (fu, fl) } else { - (fl_, fu_) + (fl, fu) }; Ok(SweepParams { fs,