view yetilab/transform/window.yeti @ 178:032c4986b6b0

Implement and test matrix concat
author Chris Cannam
date Thu, 02 May 2013 21:58:58 +0100
parents d0abc9afe608
children 26111c11d8e4
line wrap: on
line source

module yetilab.transform.window;

b = load yetilab.block.block;
bf = load yetilab.block.blockfuncs;

cosinewin a0 a1 a2 a3 n =
    b.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 = b.consts 0.5;

bartlett n =
    b.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 (b.length first);
             map (bf.multiply window) frames);
    esac;

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