diff yetilab/signal/window.yeti @ 265:c7efd12c27c5

Window fixes and tests
author Chris Cannam
date Thu, 23 May 2013 13:21:05 +0100
parents 046a2e323716
children 46d2923a04ab
line wrap: on
line diff
--- a/yetilab/signal/window.yeti	Thu May 23 11:21:30 2013 +0100
+++ b/yetilab/signal/window.yeti	Thu May 23 13:21:05 2013 +0100
@@ -29,6 +29,34 @@
     Periodic (): cosineWindowPeriodic;
     esac a0 a1 a2 a3 n;
 
+bartlettSymmetric n =
+    if n < 2 then vec.ones n
+    else
+        vec.fromList
+           (n1 = n - 1;
+            h = int (n1 / 2);
+            concat [
+                map do i:
+                    2 * i / n1
+                    done [0..h],
+                map do i:
+                    2 - (2 * i / n1)
+                    done [h+1..n1]
+                ]);
+    fi;
+
+bartlettPeriodic n = 
+    if n < 2 then vec.ones n
+    else
+        vec.slice (bartlettSymmetric (n+1)) 0 n;
+    fi;
+
+bartlett sampling =
+    case sampling of
+    Symmetric (): bartlettSymmetric;
+    Periodic (): bartlettPeriodic;
+    esac;
+
 hann = cosineWindow 0.5 0.5 0.0 0.0;
 hamming = cosineWindow 0.54 0.46 0.0 0.0;
 blackman = cosineWindow 0.42 0.50 0.08 0.0;
@@ -38,19 +66,7 @@
 
 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]
-            ]);
-
-windowFunction type options n =
+windowFunction type options =
    (var sampling = Periodic ();
     for options \case of
         Symmetric s: if s then sampling := Symmetric () fi
@@ -63,7 +79,7 @@
     BlackmanNuttall (): blackmanNuttall sampling;
     BlackmanHarris (): blackmanHarris sampling;
     Boxcar (): boxcar;
-    Bartlett (): bartlett;
+    Bartlett (): bartlett sampling;
     esac);
 
 windowed windowFunc frames =
@@ -82,7 +98,8 @@
 nuttall = nuttall (Periodic ()), 
 blackmanNuttall = blackmanNuttall (Periodic ()), 
 blackmanHarris = blackmanHarris (Periodic ()),
-boxcar, bartlett, 
+boxcar,
+bartlett = bartlett (Periodic ()), 
 windowFunction,
 windowed
 };