lasprs 0.14.3

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
Documentation
//!
//! Provides code to estimate (cross)[PowerSpectra], averaged power spectra
//! [AvPowerSpectra] using
//! Welch' method, and windows for time-windowing the data with non-rectangular
//! windows (also known as 'tapers').
//!
mod aps;
mod apsmode;
mod apssettings;
mod cpssettings;
mod error;
mod fft;
mod freqsmooth;
mod ps;
mod spectrogram;

use crate::*;

pub use crate::common::Window;
pub use aps::AvPowerSpectra;
pub use apsmode::ApsMode;
pub use apssettings::{ApsSettings, ApsSettingsBuilder};
pub use cpssettings::{CPSSettings, CPSSettingsBuilder};
pub use error::*;
#[cfg(feature = "python-bindings")]
pub(crate) use freqsmooth::smoothSpectralData_py;
pub use freqsmooth::{SmoothingType, SmoothingWidth, smoothSpectralData};
pub use ps::{CPSResult, PowerSpectra};
pub use spectrogram::{SpectroGramEngine, SpectrogramResult};

/// Returns the frequency vector for a given sample rate and FFT size.
///
/// # Arguments
///
/// * `samplerate` - The sample rate of the signal.
/// * `nfft` - The FFT size.
///
/// # Panics
///
/// Panics if `nfft` is 0
///
/// # Returns
///
/// A vector of frequencies, starting at 0 Hz, ending at the Nyquist frequency.
pub fn getFreq(samplerate: StrictlyPositive, nfft: usize) -> Array1<Flt> {
    if nfft == 0 {
        panic!("nfft must be > 0");
    }
    let df = *samplerate / nfft as Flt;
    let K = nfft / 2 + 1;
    Array1::linspace(0., (K as Flt - 1.) * df, K)
}

#[cfg(feature = "python-bindings")]
#[gen_stub_pyfunction]
#[pyfunction(name = "getFreq")]
/// Wrapper function for `getFreq` that returns a Python array. Applies
/// pre-check on inputs to prevent GIGO. Raises an error if `nfft` is 0, of if
/// Fs <= 0.
pub(crate) fn getFreq_py(
    py: Python<'_>,
    fs: StrictlyPositive,
    nfft: usize,
) -> PyResult<Bound<PyArray1<Flt>, '_>> {
    if nfft == 0 {
        Err(PyValueError::new_err("nfft must be > 0"))
    } else {
        let freq = getFreq(fs, nfft);
        Ok(freq.into_pyarray(py))
    }
}