signal::window
Window functions, as SciPy's scipy.signal.windows: symmetric by
default (for filter design); sym: false gives the periodic form
(for spectral analysis), the first m points of the m + 1 window.
Enums
WindowSource
pub enum WindowA window by name, for the functions that take one (firwin,
welch, stft, ...). Custom passes your own coefficients, which
must have the length the function needs.
use signal::window::{Window, get};
let w = try get(Window::Kaiser(8.6), 5);
println(w.len()); // 5
All ones (no window).
Shape parameter beta (0 is boxcar, 5 is close to Hamming, 8.6 to Blackman).
Taper fraction alpha in [0, 1] (0 is boxcar, 1 is Hann).
Standard deviation in samples.
Your own coefficients.
Functions
hannSource
pub fn hann(m: usize, sym: bool = true) throws (SignalError) -> Vector<f64> The Hann window 0.5 - 0.5 cos(2 pi n / (m - 1)).
println(try signal::window::hann(5)); // [0.0, 0.5, 1.0, 0.5, 0.0]
hammingSource
pub fn hamming(m: usize, sym: bool = true) throws (SignalError) -> Vector<f64> The Hamming window 0.54 - 0.46 cos(2 pi n / (m - 1)).
println(try signal::window::hamming(3)); // [0.08, 1.0, 0.08]
blackmanSource
pub fn blackman(m: usize, sym: bool = true) throws (SignalError) -> Vector<f64> The Blackman window 0.42 - 0.5 cos(2 pi n / (m - 1)) + 0.08 cos(4 pi n / (m - 1)).
println(try signal::window::blackman(3)); // [0.0, 1.0, 0.0] (to rounding)
bartlettSource
pub fn bartlett(m: usize, sym: bool = true) throws (SignalError) -> Vector<f64> The triangular Bartlett window, zero at both ends.
println(try signal::window::bartlett(5)); // [0.0, 0.5, 1.0, 0.5, 0.0]
kaiserSource
pub fn kaiser(m: usize, beta: f64, sym: bool = true) throws (SignalError) -> Vector<f64> The Kaiser window I0(beta sqrt(1 - (2n / (m - 1) - 1)^2)) / I0(beta).
beta must be finite and at least 0; kaiser_beta picks it from an
attenuation.
let w = try signal::window::kaiser(5, 0.0);
println(w); // [1.0, 1.0, 1.0, 1.0, 1.0]
kaiser_betaSource
pub fn kaiser_beta(atten: f64) -> f64 The Kaiser beta for a stopband attenuation of atten dB (Kaiser's
empirical formula, as SciPy's kaiser_beta).
println(signal::window::kaiser_beta(60.0)); // 5.65..
tukeySource
pub fn tukey(m: usize, alpha: f64 = 0.5, sym: bool = true) throws (SignalError) -> Vector<f64> The Tukey (tapered cosine) window: flat in the middle, cosine
tapers over a fraction alpha of the length; alpha 0 is boxcar
and 1 is Hann.
println(try signal::window::tukey(5, alpha: 1.0)); // [0.0, 0.5, 1.0, 0.5, 0.0]
gaussianSource
pub fn gaussian(m: usize, std: f64, sym: bool = true) throws (SignalError) -> Vector<f64> The Gaussian window exp(-((n - (m - 1) / 2) / std)^2 / 2).
let w = try signal::window::gaussian(3, 1.0);
println(w); // [0.606.., 1.0, 0.606..]
getSource
pub fn get(w: Window, m: usize, sym: bool = true) throws (SignalError) -> Vector<f64> The window w with m points (sym as for each window). A
Custom one must already have m points.
use signal::window::{Window, get};
println(try get(Window::Hann, 3)); // [0.0, 1.0, 0.0]