comparison yeti/test_frequency.yeti @ 67:d6dd6e1cc00e

Plot failing test matrices
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 28 Feb 2014 17:18:54 +0000
parents bb1799a6d690
children b75c0eaaa6dd
comparison
equal deleted inserted replaced
66:3d165bf186f1 67:d6dd6e1cc00e
5 vec = load may.vector; 5 vec = load may.vector;
6 win = load may.signal.window; 6 win = load may.signal.window;
7 mm = load may.mathmisc; 7 mm = load may.mathmisc;
8 cm = load may.matrix.complex; 8 cm = load may.matrix.complex;
9 syn = load may.stream.syntheticstream; 9 syn = load may.stream.syntheticstream;
10 plot = load may.plot;
10 11
11 { cqt } = load cqt; 12 { cqt } = load cqt;
12 13
13 // Test with a single windowed sinusoid, repeating at various frequencies 14 // Test with a single windowed sinusoid, repeating at various frequencies
14 15
29 bpo = 4; // fairly arbitrary 30 bpo = 4; // fairly arbitrary
30 31
31 testFreqs = map (* 5) [ 0..10 ]; 32 testFreqs = map (* 5) [ 0..10 ];
32 duration = sampleRate * 2; 33 duration = sampleRate * 2;
33 34
35 threshold = 0.05;
36
34 streamBuilder = sinTestStream sampleRate duration; 37 streamBuilder = sinTestStream sampleRate duration;
35 38
36 binForFreq f = 39 binForFreq f =
37 mm.round (bpo * mm.log2 (f / cqmin)) - 1; 40 mm.round (bpo * mm.log2 (f / cqmin)) - 1;
38 41
42 str = streamBuilder f; 45 str = streamBuilder f;
43 cq = cqt { maxFreq = cqmax, minFreq = cqmin, binsPerOctave = bpo } str; 46 cq = cqt { maxFreq = cqmax, minFreq = cqmin, binsPerOctave = bpo } str;
44 m = mat.concatHorizontal (map cm.magnitudes cq.output); 47 m = mat.concatHorizontal (map cm.magnitudes cq.output);
45 // println "binFrequencies = \(cq.kernel.binFrequencies)"; 48 // println "binFrequencies = \(cq.kernel.binFrequencies)";
46 // println "binForFreq \(f) = \(binForFreq f)"; 49 // println "binForFreq \(f) = \(binForFreq f)";
50 var colno = 0;
47 success = all id 51 success = all id
48 (map do c: 52 (map do c:
49 // passes test if the correct max bin, or the expected max 53 // passes test if the correct max bin, or the expected max
50 // is out of range, or if all bins are below a threshold 54 // is out of range, or if all bins are below a threshold
51 expected = binForFreq f; 55 expected = binForFreq f;
52 good = 56 good =
53 (expected < 0 or expected >= vec.length c) or 57 (expected < 0 or expected >= vec.length c) or
54 (vec.max c < 0.001) or 58 (vec.max c < threshold) or
55 (vec.maxindex c == binForFreq f); 59 (vec.maxindex c == binForFreq f);
56 if (not good) then 60 if (not good) then
57 println " * bad! maxindex \(vec.maxindex c) != expected \(binForFreq f) for freq \(f) in column: \(vec.list c)"; 61 println " * bad! maxindex \(vec.maxindex c) != expected \(binForFreq f) for freq \(f) in column \(colno) of \(mat.width m): column is \(vec.list c)";
58 println "matrix is:"; 62 println "matrix is:";
59 mat.print m; 63 mat.print m;
64 chart = plot.plot [Grid m];
65 sleep 100;
66 chart#dispose();
60 else 67 else
61 print "✓"; 68 print "✓";
62 fi; 69 fi;
70 colno := colno + 1;
63 good; 71 good;
64 done (mat.asColumns m)); 72 done (mat.asColumns m));
65 success; 73 success;
66 ) done 74 ) done
67 testFreqs; 75 testFreqs;