Mercurial > hg > octave-nkf
annotate scripts/signal/ifftshift.m @ 15263:2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
* strread.m: fix regexprep regular expression, test added, improved format specifier parsing
* textscan.m: test added
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Thu, 30 Aug 2012 20:52:40 +0200 |
parents | f3d52523cde1 |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12676
diff
changeset
|
1 ## Copyright (C) 1997-2012 Vincent Cautaerts |
5820 | 2 ## |
7016 | 3 ## This file is part of Octave. |
4 ## | |
5820 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5820 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5820 | 18 |
19 ## -*- texinfo -*- | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
20 ## @deftypefn {Function File} {} ifftshift (@var{x}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
21 ## @deftypefnx {Function File} {} ifftshift (@var{x}, @var{dim}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
22 ## Undo the action of the @code{fftshift} function. For even length |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
23 ## @var{x}, @code{fftshift} is its own inverse, but odd lengths differ |
5820 | 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 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
33 function retval = ifftshift (x, dim) |
5820 | 34 |
35 retval = 0; | |
36 | |
37 if (nargin != 1 && nargin != 2) | |
6046 | 38 print_usage (); |
5820 | 39 endif |
40 | |
41 if (nargin == 2) | |
7208 | 42 if (! isscalar (dim)) |
5820 | 43 error ("ifftshift: dimension must be an integer scalar"); |
44 endif | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
45 nd = ndims (x); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
46 sz = size (x); |
5820 | 47 sz2 = floor (sz(dim) / 2); |
12676
2783fa95cab7
Use common code idiom for creating cell array for indexing ND-arrays
Rik <octave@nomad.inbox5.com>
parents:
12541
diff
changeset
|
48 idx = repmat ({':'}, nd, 1); |
7208 | 49 idx{dim} = [sz2+1:sz(dim), 1:sz2]; |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
50 retval = x(idx{:}); |
5820 | 51 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
52 if (isvector (x)) |
12536
7d9dbe4c803b
Fix bug #32873, ifftshift fails.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
53 xl = length (x); |
7d9dbe4c803b
Fix bug #32873, ifftshift fails.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
54 xx = floor (xl/2); |
7d9dbe4c803b
Fix bug #32873, ifftshift fails.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
55 retval = x([xx+1:xl, 1:xx]); |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
56 elseif (ismatrix (x)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
57 nd = ndims (x); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
58 sz = size (x); |
5820 | 59 sz2 = floor (sz ./ 2); |
60 idx = cell (); | |
8507 | 61 for i = 1:nd |
5820 | 62 idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)]; |
63 endfor | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
64 retval = x(idx{:}); |
5820 | 65 else |
66 error ("ifftshift: expecting vector or matrix argument"); | |
67 endif | |
68 endif | |
69 | |
70 endfunction | |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
71 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
73 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
74 %! x = [0:7]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
75 %! y = ifftshift (x); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 %! assert (y, [4 5 6 7 0 1 2 3]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
77 %! assert (ifftshift (y), x); |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
78 |
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
79 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
80 %! x = [0:6]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
81 %! y = ifftshift (x); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
82 %! assert (y, [3 4 5 6 0 1 2]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 %! assert (ifftshift (y), [6 0 1 2 3 4 5]); |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
84 |
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
85 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
86 %! x = [0:7]'; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
87 %! y = ifftshift (x); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
88 %! assert (y, [4;5;6;7;0;1;2;3]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
89 %! assert (ifftshift (y), x); |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
90 |
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
91 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
92 %! x = [0:6]'; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
93 %! y = ifftshift (x); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
94 %! assert (y, [3;4;5;6;0;1;2]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
95 %! assert (ifftshift (y), [6;0;1;2;3;4;5]); |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
96 |
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
97 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
98 %! x = [0:3]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %! x = [x;2*x;3*x+1;4*x+1]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
100 %! y = ifftshift (x); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
101 %! assert (y, [[7 10 1 4];[9 13 1 5];[2 3 0 1];[4 6 0 2]]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
102 %! assert (ifftshift (y), x); |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
103 |
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
104 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 %! x = [0:3]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 %! x = [x;2*x;3*x+1;4*x+1]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
107 %! y = ifftshift (x,1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
108 %! assert (y, [[1 4 7 10];[1 5 9 13];[0 1 2 3];[0 2 4 6]]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
109 %! assert (ifftshift (y,1), x); |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
110 |
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
111 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
112 %! x = [0:3]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
113 %! x = [x;2*x;3*x+1;4*x+1]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
114 %! y = ifftshift (x,2); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
115 %! assert (y, [[2 3 0 1];[4 6 0 2];[7 10 1 4];[9 13 1 5]]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
116 %! assert (ifftshift (y,2), x); |
12541
dd2c70b30f28
Add tests for ifftshift.m
Robert T. Short <octave@phaselockedsystems.com.com>
parents:
12536
diff
changeset
|
117 |