# HG changeset patch # User Chris Cannam # Date 1367103375 -3600 # Node ID e16e42c55a20b1c46cb6c80df626f8918820e0aa # Parent cb5ab186f1468b3aee4c11bd4319fe6cdf295b38 Add autocorrelation diff -r cb5ab186f146 -r e16e42c55a20 yetilab/feature/features.yeti --- a/yetilab/feature/features.yeti Sat Apr 27 17:09:48 2013 +0100 +++ b/yetilab/feature/features.yeti Sat Apr 27 23:56:15 2013 +0100 @@ -1,15 +1,18 @@ module yetilab.feature.features; +block = load yetilab.block.block; cplx = load yetilab.block.complex; fr = load yetilab.stream.framer; -specdiff frame1 frame2 = - sum (map2 do a b: abs(cplx.magnitude b - cplx.magnitude a) done - frame1 frame2); +magdiff frame1 frame2 = + sum (map2 do a b: abs(a - b) done (block.data frame1) (block.data frame2)); emptyFrameFor frames = - if empty? frames then array [] else cplx.zeros (length (head frames)) fi; + block.zeros + if empty? frames then 0 + else block.length (head frames) + fi; features featureFunc frames = (featuresOf prev frames = @@ -19,13 +22,14 @@ esac; featuresOf (emptyFrameFor frames) frames); -featuresOfFile featureFunc file = - features featureFunc - (fr.frequencyDomainFramesOfFile { framesize = 1024, hop = 512 } file); +specdiff frames = + features magdiff (map cplx.magnitudes frames); + +specdiffOfFile parameters filename = + specdiff (fr.frequencyDomainFramesOfFile parameters filename); { specdiff, - features, - featuresOfFile + specdiffOfFile, } diff -r cb5ab186f146 -r e16e42c55a20 yetilab/signal/autocorrelation.yeti --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/signal/autocorrelation.yeti Sat Apr 27 23:56:15 2013 +0100 @@ -0,0 +1,26 @@ + +module yetilab.signal.autocorrelation; + +acf len series = + (a = array series; + map do i: + sum (map do j: + a[j] * a[j-i] + done [i..length a - 1]) + done [0..len-1]); + +acfNormalised len series = + (n = length series; + map2 do v i: v / (n - i) done (acf len series) [0..len-1]); + +acfUnityNormalised len series = + (a = acfNormalised len series; + max = head (sortBy (>) a); + map (/ max) a); + +{ + acf, + acfNormalised, + acfUnityNormalised, +} + diff -r cb5ab186f146 -r e16e42c55a20 yetilab/signal/test/test_signal.yeti --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/signal/test/test_signal.yeti Sat Apr 27 23:56:15 2013 +0100 @@ -0,0 +1,24 @@ +module yetilab.signal.test.test_signal; + +{ acf, acfNormalised, acfUnityNormalised } = load yetilab.signal.autocorrelation; + +{ compare } = load yetilab.test.test; + +[ + +"unnormalised": \( + compare (acf 12 (array [1,0,0, 1,0,0, 1,0,0, 1,0,0])) + [4,0,0, 3,0,0, 2,0,0, 1,0,0 ]; +), + +"normalised": \( + compare (acfNormalised 9 (array [1,0,0, 1,0,0, 1,0,0, 1,0,0])) + [4/12,0,0, 3/9,0,0, 2/6,0,0 ]; +), + +"normalisedUnity": \( + compare (acfUnityNormalised 9 (array [1,0,0, 1,0,0, 1,0,0, 1,0,0])) + [1,0,0, 1,0,0, 1,0,0 ]; +), + +] is hash boolean>; diff -r cb5ab186f146 -r e16e42c55a20 yetilab/test/all.yeti --- a/yetilab/test/all.yeti Sat Apr 27 17:09:48 2013 +0100 +++ b/yetilab/test/all.yeti Sat Apr 27 23:56:15 2013 +0100 @@ -11,7 +11,8 @@ "fft" : load yetilab.transform.test.test_fft, "vamppost" : load yetilab.vamp.test.test_vamppost, "matrix" : load yetilab.matrix.test.test_matrix, -"plot" : load yetilab.plot.test.test_plot +"plot" : load yetilab.plot.test.test_plot, +"signal" : load yetilab.signal.test.test_signal, ]; bad = sum (mapHash do name testHash: runTests name testHash done tests);