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@266: close aa bb = all id (map2 do a b: (abs (a - b) < 0.0001) 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@266: "hann": \( Chris@266: compareUsing close (vec.list (win.hann 10)) [ Chris@266: 0, 0.0955, 0.3455, 0.6545, 0.9045, Chris@266: 1.0000, 0.9045, 0.6545, 0.3455, 0.0955, Chris@266: ] and Chris@266: compareUsing close Chris@266: (vec.list (win.windowFunction (Hann ()) [ Symmetric true ] 10)) [ Chris@266: 0, 0.1170, 0.4132, 0.7500, 0.9698, Chris@266: 0.9698, 0.7500, 0.4132, 0.1170, 0, Chris@266: ] Chris@266: ), Chris@266: Chris@266: "hamming": \( Chris@266: compareUsing close (vec.list (win.hamming 10)) [ Chris@266: 0.0800, 0.1679, 0.3979, 0.6821, 0.9121, Chris@266: 1.0000, 0.9121, 0.6821, 0.3979, 0.1679, Chris@266: ] and Chris@266: compareUsing close Chris@266: (vec.list (win.windowFunction (Hamming ()) [ Symmetric true ] 10)) [ Chris@266: 0.0800, 0.1876, 0.4601, 0.7700, 0.9723, Chris@266: 0.9723, 0.7700, 0.4601, 0.1876, 0.0800, Chris@266: ] Chris@266: ), Chris@266: Chris@266: "blackman": \( Chris@266: compareUsing close (vec.list (win.blackman 10)) [ Chris@266: 0, 0.0402, 0.2008, 0.5098, 0.8492, Chris@266: 1.0000, 0.8492, 0.5098, 0.2008, 0.0402, Chris@266: ] and Chris@266: compareUsing close Chris@266: (vec.list (win.windowFunction (Blackman ()) [ Symmetric true ] 10)) [ Chris@266: 0, 0.0509, 0.2580, 0.6300, 0.9511, Chris@266: 0.9511, 0.6300, 0.2580, 0.0509, 0, Chris@266: ] Chris@266: ), Chris@266: Chris@266: "blackmanHarris": \( Chris@266: compareUsing close (vec.list (win.blackmanHarris 10)) [ Chris@266: 0.0001, 0.0110, 0.1030, 0.3859, 0.7938, Chris@266: 1.0000, 0.7938, 0.3859, 0.1030, 0.0110, Chris@266: ] and Chris@266: compareUsing close Chris@266: (vec.list (win.windowFunction (BlackmanHarris ()) [ Symmetric true ] 10)) [ Chris@266: 0.0001, 0.0151, 0.1470, 0.5206, 0.9317, Chris@266: 0.9317, 0.5206, 0.1470, 0.0151, 0.0001, Chris@266: ] Chris@266: ), Chris@266: Chris@266: "degenerate": \( Chris@266: all id (map do type: Chris@266: f = functions[type]; Chris@266: periodic = f; Chris@266: symmetric = win.windowFunction type [ Symmetric true ]; Chris@266: (compare (vec.list (periodic 0)) [] and Chris@266: compare (vec.list (periodic 1)) [1] and Chris@266: compare (vec.list (symmetric 0)) [] and Chris@266: compare (vec.list (symmetric 1)) [1]) Chris@266: or (eprintln "** failed window type: \(type)"; false) Chris@266: done (keys functions)); Chris@266: ), Chris@266: Chris@265: ] is hash boolean>; Chris@265: