changelog shortlog tags changeset files revisions annotate raw

scripts/signal/ifftshift.m

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