5820
|
1 ## Copyright (C) 1997 by Vincent Cautaerts |
|
2 ## |
|
3 ## Octave is free software; you can redistribute it and/or modify it |
|
4 ## under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
|
8 ## Octave is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with Octave; see the file COPYING. If not, write to the Free |
|
15 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
16 ## 02110-1301, USA. |
|
17 |
|
18 ## -*- texinfo -*- |
|
19 ## @deftypefn {Function File} {} ifftshift (@var{v}) |
|
20 ## @deftypefnx {Function File} {} ifftshift (@var{v}, @var{dim}) |
|
21 ## Undo the action of the @code{fftshift} function. For even length |
|
22 ## @var{v}, @code{fftshift} is its own inverse, but odd lengths differ |
|
23 ## slightly. |
|
24 ## @end deftypefn |
|
25 |
|
26 ## Author: Vincent Cautaerts <vincent@comf5.comm.eng.osaka-u.ac.jp> |
|
27 ## Created: July 1997 |
|
28 ## Adapted-By: jwe |
|
29 ## Modified-By: Paul Kienzle, converted from fftshift |
|
30 ## Modified-By: David Bateman, add NDArray capability and option dim arg |
|
31 |
|
32 function retval = ifftshift (V, dim) |
|
33 |
|
34 retval = 0; |
|
35 |
|
36 if (nargin != 1 && nargin != 2) |
6046
|
37 print_usage (); |
5820
|
38 endif |
|
39 |
|
40 if (nargin == 2) |
|
41 if (!isscalar (dim)) |
|
42 error ("ifftshift: dimension must be an integer scalar"); |
|
43 endif |
|
44 nd = ndims (V); |
|
45 sz = size (V); |
|
46 sz2 = floor (sz(dim) / 2); |
|
47 idx = cell (); |
|
48 for i=1:nd |
|
49 idx {i} = 1:sz(i); |
|
50 endfor |
|
51 idx {dim} = [sz2+1:sz(dim), 1:sz2]; |
|
52 retval = V (idx{:}); |
|
53 else |
|
54 if (isvector (V)) |
|
55 x = length (V); |
|
56 xx = floor (x/2); |
|
57 retval = V([xx+1:x, 1:xx]); |
|
58 elseif (ismatrix (V)) |
|
59 nd = ndims (V); |
|
60 sz = size (V); |
|
61 sz2 = floor (sz ./ 2); |
|
62 idx = cell (); |
|
63 for i=1:nd |
|
64 idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)]; |
|
65 endfor |
|
66 retval = V (idx{:}); |
|
67 else |
|
68 error ("ifftshift: expecting vector or matrix argument"); |
|
69 endif |
|
70 endif |
|
71 |
|
72 endfunction |