changeset 370:2af1885c3694

Add Kaiser based on bandwidth in Hz; add "dirac" window which contains only a single 1
author Chris Cannam
date Tue, 23 Jul 2013 15:19:01 +0100
parents 8c46a78594ee
children 339d6b71bbda
files may/signal/test/test_window.yeti may/signal/window.yeti
diffstat 2 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/may/signal/test/test_window.yeti	Tue Jul 23 15:17:50 2013 +0100
+++ b/may/signal/test/test_window.yeti	Tue Jul 23 15:19:01 2013 +0100
@@ -151,6 +151,12 @@
     ]
 ),
 
+"dirac": \(
+    compareUsing close (vec.list (win.dirac 1)) [ 1 ] and
+        compareUsing close (vec.list (win.dirac 5)) [ 0, 0, 1, 0, 0 ] and
+        compareUsing close (vec.list (win.dirac 6)) [ 0, 0, 0, 1, 0, 0 ]
+),
+
 "sinc": \(
     compareUsing close (vec.list (win.sinc 1 5)) [ 0, 0, 1, 0, 0 ] and
         compareUsing close (vec.list (win.sinc 2 5)) [ 0, 0, 1, 0, 0 ] and
--- a/may/signal/window.yeti	Tue Jul 23 15:17:50 2013 +0100
+++ b/may/signal/window.yeti	Tue Jul 23 15:19:01 2013 +0100
@@ -69,6 +69,18 @@
 boxcar n = vec.ones n;
 
 /**
+ * Vector of size n with the "middle" sample equal to 1 and all others
+ * equal to 0. The middle sample is sample (n-1)/2 for odd n or n/2+1
+ * for even n.
+ */
+dirac n =
+    if n < 2 then vec.ones n
+    else 
+        n0 = if n % 2 == 0 then n/2 else (n-1)/2 fi;
+        vec.concat [ vec.zeros n0, vec.ones 1, vec.zeros n0 ]
+    fi;
+
+/**
  * Make a vector of size n containing the values of sinc(x) with
  * x=0 in the middle, i.e. at sample (n-1)/2 for odd n or n/2+1 for
  * even n, such that the distance from -pi to pi (the point at
@@ -115,16 +127,23 @@
     kaiser 𝛽 n);
 
 /**
-  Kaiser window with sidelobe attenuation of 𝛼 dB and transition width
-  of (tw * samplerate) / (2 * pi)
+  Kaiser window with sidelobe attenuation of 𝛼 dB and transition 
+  bandwidth of (tw * samplerate) / (2 * pi)
 */
-kaiserFor 𝛼 tw =
+kaiserForTransitionLength 𝛼 tw =
    (m = if 𝛼 > 21 
         then Math#ceil((𝛼 - 7.95) / (2.285 * tw))
         else Math#ceil(5.79 / tw)
         fi;
     kaiserForAttenuation 𝛼 (m+1));
 
+/**
+  Kaiser window with sidelobe attenuation of 𝛼 dB and transition
+  bandwidth of tbw Hz at the given sampleRate
+*/
+kaiserForBandwidth 𝛼 tbw samplerate =
+    kaiserForTransitionLength 𝛼 ((tbw * 2 * pi) / samplerate);
+
 windowFunction type options =
    (var sampling = Periodic ();
     var 𝛽 = 4;
@@ -163,8 +182,9 @@
 blackmanHarris = blackmanHarris (Periodic ()),
 boxcar,
 bartlett = bartlett (Periodic ()), 
+dirac,
 sinc,
-kaiser, kaiserForAttenuation, kaiserFor,
+kaiser, kaiserForAttenuation, kaiserForTransitionLength, kaiserForBandwidth,
 windowFunction,
 windowed
 };