apodize 0.2.0

iterators that yield generalized cosine, hanning, hamming, blackman, nuttall and triangular windows

Crate apodize [] [src]

rust iterators that yield generalized cosine, hanning, hamming, blackman, nuttall and triangular windows

useful for smoothing the sharp discontinuities at the edges (beginning and end) of each slice of samples when doing a short time fourier transform. windowing also improves temporal resolution by making the signal near the time being analyzed have higher weight than the signal further away from the time being analyzed.

to use add apodize = "*" to the [dependencies] section of your Cargo.toml and call extern crate apodize; in your code.

all functions use f64s. previously they were generic over the floating type used. this was removed because it introduced a lot of complexity. if you need f32s just .map(|x| x as f32) over the iterator.

example

you will most likely want to collect the yielded values in a vector and then multiply that window vector repeatedly with some data vectors to apodize them.

here is an example of that for a hanning window (hamming, blackman and nuttall are analogous).

use std::ops::Mul;

#[macro_use]
extern crate nalgebra;
use nalgebra::{ApproxEq, DVec};

#[macro_use]
extern crate apodize;
use apodize::{hanning_iter};

fn main() {
    // create a hanning window iterator of size 7
    // and collect the values it yields in an nalgebra::DVec.
    let window = hanning_iter(7).collect::<DVec<_>>();

    assert_approx_eq_ulps!(
        window,
        dvec![
            0.0,
            0.24999999999999994,
            0.7499999999999999,
            1.0,
            0.7500000000000002,
            0.25,
            0.0],
        10);

    // some data we want to apodize (multiply with the window)
    let data: DVec<f64> = dvec![1., 2., 3., 4., 5., 6., 7.];

    // multiply data with window
    let windowed_data = window.mul(data);

    assert_approx_eq_ulps!(
        windowed_data,
        dvec![
            0.0,
            0.4999999999999999,
            2.2499999999999996,
            4.0,
            3.750000000000001,
            1.5,
            0.0],
        10);
}

Macros

dvec!

build an nalgebra::DVec as easy as a std::Vec. for shorter, more readable code in tests and examples.

Structs

CosineWindowIter

holds the window coefficients and iteration state of an iterator for a cosine window

TriangularWindowIter

holds the iteration state of an iterator for a triangular window

Functions

blackman_iter

returns an iterator that yields the values for a blackman window of size

cosine_at

returns the value of the cosine window of size with the coefficients a, b, c and d at index

cosine_iter

returns an iterator that yields the values for a cosine window of size with the coefficients a, b, c and d

hamming_iter

returns an iterator that yields the values for a hamming window of size

hanning_iter

returns an iterator that yields the values for a hanning window of size

nuttall_iter

returns an iterator that yields the values for a nuttall window of size

triangular_at

returns the value of the triangular window of size at index

triangular_iter

returns an iterator that yields the values for a triangular window if l = size - 1 then the outermost values of the window are 0. if l = size then the outermost values of the window are higher. if l = size + 1 then the outermost values of the window are even higher.