changeset 266:46d2923a04ab

Further tests and fixes
author Chris Cannam
date Thu, 23 May 2013 13:34:27 +0100
parents c7efd12c27c5
children 66346df10f70
files yetilab/signal/test/test_window.yeti yetilab/signal/window.yeti
diffstat 2 files changed, 70 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/signal/test/test_window.yeti	Thu May 23 13:21:05 2013 +0100
+++ b/yetilab/signal/test/test_window.yeti	Thu May 23 13:34:27 2013 +0100
@@ -17,7 +17,7 @@
     Bartlett () : win.bartlett,
 ];
 
-close aa bb = all id (map2 do a b: (abs (a - b) < 0.00001) done aa bb);
+close aa bb = all id (map2 do a b: (abs (a - b) < 0.0001) done aa bb);
 
 isSymmetric a =
    (len = (vec.length a);
@@ -103,5 +103,66 @@
        compare (vec.list (b 5)) [0,1/2,1,1/2,0]
 ),
 
+"hann": \(
+    compareUsing close (vec.list (win.hann 10)) [
+        0, 0.0955, 0.3455, 0.6545, 0.9045,
+        1.0000, 0.9045, 0.6545, 0.3455, 0.0955,
+    ] and
+    compareUsing close 
+       (vec.list (win.windowFunction (Hann ()) [ Symmetric true ] 10)) [
+        0, 0.1170, 0.4132, 0.7500, 0.9698,
+        0.9698, 0.7500, 0.4132, 0.1170, 0,
+    ]
+),
+
+"hamming": \(
+    compareUsing close (vec.list (win.hamming 10)) [
+        0.0800, 0.1679, 0.3979, 0.6821, 0.9121,
+        1.0000, 0.9121, 0.6821, 0.3979, 0.1679,
+    ] and
+    compareUsing close 
+       (vec.list (win.windowFunction (Hamming ()) [ Symmetric true ] 10)) [
+        0.0800, 0.1876, 0.4601, 0.7700, 0.9723,
+        0.9723, 0.7700, 0.4601, 0.1876, 0.0800,
+    ]
+),
+
+"blackman": \(
+    compareUsing close (vec.list (win.blackman 10)) [
+        0, 0.0402, 0.2008, 0.5098, 0.8492,
+        1.0000, 0.8492, 0.5098, 0.2008, 0.0402,
+    ] and
+    compareUsing close 
+       (vec.list (win.windowFunction (Blackman ()) [ Symmetric true ] 10)) [
+        0, 0.0509, 0.2580, 0.6300, 0.9511,
+        0.9511, 0.6300, 0.2580, 0.0509, 0,
+    ]
+),
+
+"blackmanHarris": \(
+    compareUsing close (vec.list (win.blackmanHarris 10)) [
+        0.0001, 0.0110, 0.1030, 0.3859, 0.7938,
+        1.0000, 0.7938, 0.3859, 0.1030, 0.0110,
+    ] and
+    compareUsing close 
+       (vec.list (win.windowFunction (BlackmanHarris ()) [ Symmetric true ] 10)) [
+        0.0001, 0.0151, 0.1470, 0.5206, 0.9317,
+        0.9317, 0.5206, 0.1470, 0.0151, 0.0001,
+    ]
+),
+
+"degenerate": \(
+    all id (map do type:
+        f = functions[type];
+        periodic = f;
+        symmetric = win.windowFunction type [ Symmetric true ];
+       (compare (vec.list (periodic 0)) [] and
+        compare (vec.list (periodic 1)) [1] and
+        compare (vec.list (symmetric 0)) [] and
+        compare (vec.list (symmetric 1)) [1])
+            or (eprintln "** failed window type: \(type)"; false)
+    done (keys functions));
+),
+
 ] is hash<string, () -> boolean>;
 
--- a/yetilab/signal/window.yeti	Thu May 23 13:21:05 2013 +0100
+++ b/yetilab/signal/window.yeti	Thu May 23 13:34:27 2013 +0100
@@ -24,10 +24,13 @@
             done [0..n-1]));
                   
 cosineWindow a0 a1 a2 a3 sampling n =
-    case sampling of 
-    Symmetric (): cosineWindowSymmetric;
-    Periodic (): cosineWindowPeriodic;
-    esac a0 a1 a2 a3 n;
+    if n < 2 then vec.ones n
+    else
+        case sampling of 
+        Symmetric (): cosineWindowSymmetric;
+        Periodic (): cosineWindowPeriodic;
+        esac a0 a1 a2 a3 n;
+    fi;
 
 bartlettSymmetric n =
     if n < 2 then vec.ones n
@@ -64,7 +67,7 @@
 blackmanNuttall = cosineWindow 0.3635819 0.4891775 0.1365995 0.0106411;
 blackmanHarris = cosineWindow 0.35875 0.48829 0.14128 0.01168;
 
-boxcar = vec.consts 0.5;
+boxcar n = if n < 2 then vec.ones n else vec.consts 0.5 n fi;
 
 windowFunction type options =
    (var sampling = Periodic ();