Mercurial > hg > may
changeset 460:b3106795bbbf
Fix and test complex fft
author | Chris Cannam |
---|---|
date | Fri, 25 Oct 2013 11:50:35 +0100 |
parents | 2e87f815f5bc |
children | 338ef3a95d8e |
files | src/may/transform/fft.yeti src/may/transform/test/test_fft.yeti |
diffstat | 2 files changed, 32 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/transform/fft.yeti Fri Oct 25 11:50:16 2013 +0100 +++ b/src/may/transform/fft.yeti Fri Oct 25 11:50:35 2013 +0100 @@ -5,6 +5,7 @@ vec = load may.vector; complex = load may.complex; +bf = load may.vector.blockfuncs; load may.complex.type; @@ -33,21 +34,18 @@ v); unpackedToComplex len unp is number -> ~double[] -> array<cplx> = - array - (map2 complex.complex - (vec.list (vec.slice unp 0 len)) - (vec.list (vec.slice unp len (len*2)))); + (vv = bf.unzipped 2 unp; + array (map2 complex.complex (vec.list vv[0]) (vec.list vv[1]))); -complexToUnpacked len cc is number -> array<cplx> -> ~double[] = - vec.primitive - (vec.resizedTo (len*2) - (vec.fromList (map complex.real cc ++ map complex.imaginary cc))); +complexToUnpacked cc is array<cplx> -> ~double[] = + bf.zipped [ vec.fromList (map complex.real cc), + vec.fromList (map complex.imaginary cc) ]; //!!! doc: n separately as below forward n = (d = new DoubleFFT_1D(n); do cc: - arr = complexToUnpacked n cc; + arr = vec.resizedTo (n*2) (complexToUnpacked cc); d#complexForward(arr); unpackedToComplex n arr; done); @@ -56,7 +54,7 @@ inverse n = (d = new DoubleFFT_1D(n); do cc: - arr = complexToUnpacked n cc; + arr = vec.resizedTo (n*2) (complexToUnpacked cc); d#complexInverse(arr, true); unpackedToComplex n arr; done); @@ -67,7 +65,7 @@ realForward n = (d = new DoubleFFT_1D(n); do bl: - v = vec.primitive (vec.resizedTo n bl); + v = vec.resizedTo n bl; d#realForward(v); packedToComplex n v; done);
--- a/src/may/transform/test/test_fft.yeti Fri Oct 25 11:50:16 2013 +0100 +++ b/src/may/transform/test/test_fft.yeti Fri Oct 25 11:50:35 2013 +0100 @@ -1,9 +1,9 @@ module may.transform.test.test_fft; -{ realForward, realForwardMagnitude, realInverse } = load may.transform.fft; +{ forward, inverse, realForward, realForwardMagnitude, realInverse } = load may.transform.fft; { list, fromList } = load may.vector; -{ complex, magnitude } = load may.complex; +{ complex, magnitude, real, imaginary } = load may.complex; { compare } = load may.test.test; @@ -17,10 +17,17 @@ reals imags) ); +testFFTComplex rin iin rout iout = + (cin = array (map2 complex rin iin); + cout = forward (length cin) cin; + back = inverse (length cin) cout; + compare (map real cout) rout and + compare (map imaginary cout) iout and + compare back cin + ); + [ -//!!! test complex forward/inverse - "dc": \( testFFT [1,1,1,1] [4,0,0] [0,0,0]; ), @@ -48,6 +55,18 @@ testFFT [0,0,0,1] [1,0,-1] [0,1,0]; ), +"c_dc": \( + testFFTComplex [1,1,1,1] [1,1,1,1] [4,0,0,0] [4,0,0,0]; +), + +"c_cosine": \( + testFFTComplex [1,0,-1,0] [1,0,-1,0] [0,2,0,2] [0,2,0,2]; +), + +"c_sineCosine": \( + testFFTComplex [1,0,-1,0] [0,1,0,-1] [0,4,0,0] [0,0,0,0]; +), + ] is hash<string, () -> boolean>;