view yetilab/transform/window.yeti @ 222:77c6a81c577f matrix_opaque_immutable

Move block directory -> vector
author Chris Cannam
date Sat, 11 May 2013 15:58:36 +0100
parents a7f4eb1cdd72
children 9b07a28aefad
line wrap: on
line source

module yetilab.transform.window;

vec = load yetilab.vector.vector;
bf = load yetilab.vector.blockfuncs;

cosinewin a0 a1 a2 a3 n =
    vec.fromList
       (map do i:
            a0
            - a1 * cos(2 * pi * i / n)
            + a2 * cos(4 * pi * i / n)
            - a2 * cos(6 * pi * i / n)
            done [0..n-1]);
                  
hann = cosinewin 0.5 0.5 0.0 0.0;
hamming = cosinewin 0.54 0.46 0.0 0.0;
blackman = cosinewin 0.42 0.50 0.08 0.0;
nuttall = cosinewin 0.3635819 0.4891775 0.1365995 0.0106411;
blackmanHarris = cosinewin 0.35875 0.48829 0.14128 0.01168;
boxcar = vec.consts 0.5;

bartlett n =
    vec.fromList
       (m = n/2;
        concat [
            map do i:
                i / m
                done [0..m-1],
            map do i:
                1.0 - (i / m)
                done [0..m-1]
            ]);

windowed windowFunc frames =
    case frames of
        []: frames;
         _: (first = head frames;
             window = windowFunc (vec.length first);
             map (bf.multiply window) frames);
    esac;

{
cosinewin, hann, hamming, blackman, nuttall, blackmanHarris, boxcar, bartlett,
windowed
};