# Crate apodize[−][src]

**very simple 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 `extern crate apodize;`

to your code.

all iterators yield `f64`

s.
previously they were generic over the floating type used.
this was removed because it introduced complexity.
if you need `f32`

s 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).

#[macro_use] extern crate approx; extern crate apodize; fn main() { // create a hanning window iterator of size 7 // and collect the values it yields in a Vec let window = apodize::hanning_iter(7).collect::<Vec<f64>>(); let expected = vec![ 0.0, 0.24999999999999994, 0.7499999999999999, 1.0, 0.7500000000000002, 0.25, 0.0 ]; assert_ulps_eq!(window.as_slice(), expected.as_slice(), max_ulps = 10); // some data we want to apodize (multiply with the window) let data: Vec<f64> = vec![1., 2., 3., 4., 5., 6., 7.]; // multiply data with window let mut windowed_data = Vec::with_capacity(data.len()); for i in 0..window.len() { windowed_data.push(window[i] * data[i]); } let expected = vec![ 0.0, 0.4999999999999999, 2.2499999999999996, 4.0, 3.750000000000001, 1.5, 0.0 ]; assert_ulps_eq!(windowed_data.as_slice(), expected.as_slice(), max_ulps = 10); }

## 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 |

cosine_at |
returns the value of the cosine
window
of |

cosine_iter |
returns an iterator that yields the values for a cosine
window of |

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

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

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

triangular_at |
returns the value of the
[triangular window]
(https://en.wikipedia.org/wiki/Window_function#Triangular_window)
of |

triangular_iter |
returns an iterator that yields the values for a triangular
window
if |