# HG changeset patch # User Chris Cannam # Date 1356254519 0 # Node ID d239bdcdb54179244b4ca4b76345151ea4b14b68 # Parent fa49869bda5180f6c04ecb7fd76438089e5fafac Add fftshift diff -r fa49869bda51 -r d239bdcdb541 blockfuncs.yeti --- a/blockfuncs.yeti Sat Dec 22 11:19:46 2012 +0000 +++ b/blockfuncs.yeti Sun Dec 23 09:21:59 2012 +0000 @@ -21,21 +21,33 @@ for [0..len-1] do i: v[i] := v1[i] * v2[i] done; b.block v); -sqr b = - multiply b b; +sqr bl = + multiply bl bl; + +rms = + sqrt . mean . sqr; sqrt' = b.fromList . (map sqrt) . b.list; -rms = - sqrt . mean . sqr; +fftshift bl = + (len = b.length bl; + half = int(len/2 + 0.5); // round up for odd-length sequences + b.concat [b.rangeOf bl half (len-half), b.rangeOf bl 0 half]); + +ifftshift bl = + (len = b.length bl; + half = int(len/2); // round down for odd-length sequences + b.concat [b.rangeOf bl half (len-half), b.rangeOf bl 0 half]); { sum = sum', mean, multiply, sqr, sqrt = sqrt', -rms +rms, +fftshift, +ifftshift, } diff -r fa49869bda51 -r d239bdcdb541 test/test_blockfuncs.yeti --- a/test/test_blockfuncs.yeti Sat Dec 22 11:19:46 2012 +0000 +++ b/test/test_blockfuncs.yeti Sun Dec 23 09:21:59 2012 +0000 @@ -4,7 +4,7 @@ stdSqrt = sqrt; { zeros, consts, ones, fromList, list } = load block; -{ sum, mean, multiply, sqr, sqrt, rms } = load blockfuncs; +{ sum, mean, multiply, sqr, sqrt, rms, fftshift, ifftshift } = load blockfuncs; { declare, compare } = load test.test; declare [ @@ -46,5 +46,17 @@ compare ((rms . fromList) [-1,2,2]) (stdSqrt 3) ), +"fftshift": \( + compare ((list . fftshift . zeros) 0) [] and + compare ((list . fftshift . fromList) [1,2,3,4]) [3,4,1,2] and + compare ((list . fftshift . fromList) [1,2,3,4,5]) [4,5,1,2,3] +), + +"ifftshift": \( + compare ((list . ifftshift . zeros) 0) [] and + compare ((list . ifftshift . fromList) [3,4,1,2]) [1,2,3,4] and + compare ((list . ifftshift . fromList) [4,5,1,2,3]) [1,2,3,4,5] +), + ];