changeset 373:a1679a2b631c

First cut at unit test for lowpass
author Chris Cannam
date Wed, 31 Jul 2013 14:28:30 +0100
parents 2d202fae1e04
children 4ca19c9819b8
files may/stream/filter.yeti may/stream/test/test_filter.yeti
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/may/stream/filter.yeti	Tue Jul 23 15:20:27 2013 +0100
+++ b/may/stream/filter.yeti	Wed Jul 31 14:28:30 2013 +0100
@@ -437,7 +437,6 @@
    (rate = s.sampleRate;
     kw = win.kaiserForBandwidth attenuation bandwidth rate;
     filterLength = vec.length kw;
-println "filterLength = \(filterLength)";
     idealFor freq =
         bf.scaled (freq / rate)
            (win.sinc ((rate / freq) * 2) filterLength);
--- a/may/stream/test/test_filter.yeti	Tue Jul 23 15:20:27 2013 +0100
+++ b/may/stream/test/test_filter.yeti	Wed Jul 31 14:28:30 2013 +0100
@@ -4,6 +4,8 @@
 vec = load may.vector;
 bf = load may.vector.blockfuncs;
 mat = load may.matrix;
+cplx = load may.complex;
+fft = load may.transform.fft;
 syn = load may.stream.syntheticstream;
 filt = load may.stream.filter;
 
@@ -736,6 +738,32 @@
     else true fi;
 ),
 
+"lowpassed-dirac-\(name)": \(
+    n = 1000;
+    rate = 800;
+    input = syn.generated rate do x: if x == int(n/2) then 1 else 0 fi done;
+    cutoff = 200;
+    attenuation = 80;
+    bandwidth = 10;
+    output = filt.lowpassed cutoff attenuation bandwidth input;
+    outdata = mat.getRow 0 (output.read n);
+    spectrum = cplx.magnitudes (fft.realForward n outdata);
+    logspec = array (map do v: 20 * Math#log10(v) done (vec.list spectrum));
+    acceptances = map do bin:
+        freq = (rate / n) * bin;
+        db = logspec[bin];
+        good = 
+        if freq < cutoff - bandwidth/2 then (db < 0.1 and db > -0.1)
+        elif freq > cutoff + bandwidth/2 then (db < -attenuation)
+        else (db < 0.1 and db > -attenuation)
+        fi;
+        println "\(freq) Hz: \(db) dB - \(good)";
+        good
+    done [0..n/2];
+    compare acceptances (map \true [0..n/2]);
+),
+    
+
 //!!! still no tests for filters with multi-channel inputs
 
 ]);