Chris@265: Chris@265: module yetilab.signal.test.test_window; Chris@265: Chris@265: win = load yetilab.signal.window; Chris@265: vec = load yetilab.vector.vector; Chris@265: Chris@265: { compare, compareUsing } = load yetilab.test.test; Chris@265: Chris@265: functions = [ Chris@265: Hann () : win.hann, Chris@265: Hamming () : win.hamming, Chris@265: Blackman () : win.blackman, Chris@265: Nuttall () : win.nuttall, Chris@265: BlackmanNuttall () : win.blackmanNuttall, Chris@265: BlackmanHarris () : win.blackmanHarris, Chris@265: Boxcar () : win.boxcar, Chris@265: Bartlett () : win.bartlett, Chris@265: ]; Chris@265: Chris@265: close aa bb = all id (map2 do a b: (abs (a - b) < 0.00001) done aa bb); Chris@265: Chris@265: isSymmetric a = Chris@265: (len = (vec.length a); Chris@265: b = if len % 2 == 0 then Chris@265: half = vec.slice a 0 (len/2); Chris@265: vec.concat [half, vec.reversed half]; Chris@265: else Chris@265: half = vec.slice a 0 (int (len/2)); Chris@265: mid = vec.slice a (int (len/2)) (int (len/2) + 1); Chris@265: vec.concat [half, mid, vec.reversed half]; Chris@265: fi; Chris@265: compareUsing close (vec.list a) (vec.list b)); Chris@265: Chris@265: [ Chris@265: Chris@265: "windowFunction": \( Chris@265: all id (map do type: Chris@265: f = functions[type]; Chris@265: a = f 10; Chris@265: b = win.windowFunction type [ Symmetric false ] 10; Chris@265: compareUsing close (vec.list a) (vec.list b) Chris@265: or (eprintln "** failed window type: \(type)"; false) Chris@265: done (keys functions)); Chris@265: ), Chris@265: Chris@265: "symmetric-even": \( Chris@265: len = 10; Chris@265: all id (map do type: Chris@265: f = win.windowFunction type [ Symmetric true ]; Chris@265: v = f len; Chris@265: (compare (vec.length v) len and isSymmetric v) or Chris@265: (eprintln "** failed window type: \(type)"; false); Chris@265: done (keys functions)); Chris@265: ), Chris@265: Chris@265: "symmetric-odd": \( Chris@265: len = 11; Chris@265: all id (map do type: Chris@265: f = win.windowFunction type [ Symmetric true ]; Chris@265: v = f len; Chris@265: (compare (vec.length v) len and isSymmetric v) or Chris@265: (eprintln "** failed window type: \(type)"; false); Chris@265: done (keys functions)); Chris@265: ), Chris@265: Chris@265: "periodic-even": \( Chris@265: // We can't actually test whether a function is periodic, given Chris@265: // only one cycle of it! But we can make sure that all but the Chris@265: // first sample is symmetric, which is what a symmetric window Chris@265: // becomes when generated in periodic mode Chris@265: len = 10; Chris@265: all id (map do type: Chris@265: f = win.windowFunction type [ Symmetric false ]; Chris@265: v = f len; Chris@265: (compare (vec.length v) len and isSymmetric (vec.slice v 1 len)) or Chris@265: (eprintln "** failed window type: \(type)"; false); Chris@265: done (keys functions)); Chris@265: ), Chris@265: Chris@265: "periodic-odd": \( Chris@265: len = 11; Chris@265: all id (map do type: Chris@265: f = win.windowFunction type [ Symmetric false ]; Chris@265: v = f len; Chris@265: (compare (vec.length v) len and isSymmetric (vec.slice v 1 len)) or Chris@265: (eprintln "** failed window type: \(type)"; false); Chris@265: done (keys functions)); Chris@265: ), Chris@265: Chris@265: "bartlett-periodic": \( Chris@265: compare (vec.list (win.bartlett 1)) [1] and Chris@265: compare (vec.list (win.bartlett 2)) [0,1] and Chris@265: compare (vec.list (win.bartlett 3)) [0,2/3,2/3] and Chris@265: compare (vec.list (win.bartlett 4)) [0,1/2,1,1/2] Chris@265: ), Chris@265: Chris@265: "bartlett-symmetric": \( Chris@265: b = win.windowFunction (Bartlett ()) [ Symmetric true ]; Chris@265: compare (vec.list (b 1)) [1] and Chris@265: compare (vec.list (b 2)) [0,0] and Chris@265: compare (vec.list (b 3)) [0,1,0] and Chris@265: compare (vec.list (b 4)) [0,2/3,2/3,0] and Chris@265: compare (vec.list (b 5)) [0,1/2,1,1/2,0] Chris@265: ), Chris@265: Chris@265: ] is hash boolean>; Chris@265: