# HG changeset patch # User Robert T. Short # Date 1301146955 25200 # Node ID b3c158b8941c74daddf32d32f7c1023e151d90ab # Parent ccd0572e5e93c2f4684582c45f38ecdbdf650745 Add tests for fftshift.m. diff -r ccd0572e5e93 -r b3c158b8941c scripts/ChangeLog --- a/scripts/ChangeLog Fri Mar 25 13:37:11 2011 -0400 +++ b/scripts/ChangeLog Sat Mar 26 06:42:35 2011 -0700 @@ -1,3 +1,7 @@ +2011-03-26 Robert T. Short + + * signal/fftshift.m: Add tests. + 2011-03-21 Rik * signal/ifftshift.m: Fix bug #32873, ifftshift fails. diff -r ccd0572e5e93 -r b3c158b8941c scripts/signal/fftshift.m --- a/scripts/signal/fftshift.m Fri Mar 25 13:37:11 2011 -0400 +++ b/scripts/signal/fftshift.m Sat Mar 26 06:42:35 2011 -0700 @@ -83,3 +83,49 @@ endif endfunction + +%!test +%! x = [0:7]; +%! y = fftshift (x); +%! assert(y, [4 5 6 7 0 1 2 3]); +%! assert(fftshift (y), x); + +%!test +%! x = [0:6]; +%! y = fftshift (x); +%! assert(y, [4 5 6 0 1 2 3]); +%! assert(fftshift (y), [1 2 3 4 5 6 0]); + +%!test +%! x = [0:7]'; +%! y = fftshift (x); +%! assert(y, [4;5;6;7;0;1;2;3]); +%! assert(fftshift (y), x); + +%!test +%! x = [0:6]'; +%! y = fftshift (x); +%! assert(y, [4;5;6;0;1;2;3]); +%! assert(fftshift (y), [1;2;3;4;5;6;0]); + +%!test +%! x = [0:3]; +%! x = [x;2*x;3*x+1;4*x+1]; +%! y = fftshift (x); +%! assert(y, [[7 10 1 4];[9 13 1 5];[2 3 0 1];[4 6 0 2]]); +%! assert(fftshift (y), x); + +%!test +%! x = [0:3]; +%! x = [x;2*x;3*x+1;4*x+1]; +%! y = fftshift (x,1); +%! assert(y, [[1 4 7 10];[1 5 9 13];[0 1 2 3];[0 2 4 6]]); +%! assert(fftshift (y,1), x); + +%!test +%! x = [0:3]; +%! x = [x;2*x;3*x+1;4*x+1]; +%! y = fftshift (x,2); +%! assert(y, [[2 3 0 1];[4 6 0 2];[7 10 1 4];[9 13 1 5]]); +%! assert(fftshift (y,2), x); +