annotate scripts/signal/ifftshift.m @ 6046:34f96dd5441b

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