Mercurial > hg > octave-nkf
annotate scripts/signal/fftshift.m @ 10509:ddbd812d09aa
properly compress sparse matrices after assembly
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 12 Apr 2010 12:57:44 +0200 |
parents | 1bf0ce0930be |
children | be55736a0783 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1997, 1998, 2000, 2002, 2004, 2005, 2006, 2007, 2009 |
2 ## Vincent Cautaerts | |
3426 | 3 ## |
3922 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
3191 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
3191 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3191 | 19 |
3449 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} fftshift (@var{v}) | |
4844 | 22 ## @deftypefnx {Function File} {} fftshift (@var{v}, @var{dim}) |
3449 | 23 ## Perform a shift of the vector @var{v}, for use with the @code{fft} |
24 ## and @code{ifft} functions, in order the move the frequency 0 to the | |
3499 | 25 ## center of the vector or matrix. |
3191 | 26 ## |
4077 | 27 ## If @var{v} is a vector of @math{N} elements corresponding to @math{N} |
3499 | 28 ## time samples spaced of @math{Dt} each, then @code{fftshift (fft |
3449 | 29 ## (@var{v}))} corresponds to frequencies |
3191 | 30 ## |
3449 | 31 ## @example |
4077 | 32 ## f = ((1:N) - ceil(N/2)) / N / Dt |
3449 | 33 ## @end example |
3191 | 34 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
35 ## If @var{v} is a matrix, the same holds for rows and columns. If |
4844 | 36 ## @var{v} is an array, then the same holds along each dimension. |
37 ## | |
38 ## The optional @var{dim} argument can be used to limit the dimension | |
39 ## along which the permutation occurs. | |
3449 | 40 ## @end deftypefn |
3191 | 41 |
42 ## Author: Vincent Cautaerts <vincent@comf5.comm.eng.osaka-u.ac.jp> | |
43 ## Created: July 1997 | |
44 ## Adapted-By: jwe | |
45 | |
4844 | 46 function retval = fftshift (V, dim) |
3191 | 47 |
48 retval = 0; | |
49 | |
4844 | 50 if (nargin != 1 && nargin != 2) |
6046 | 51 print_usage (); |
3191 | 52 endif |
53 | |
4844 | 54 if (nargin == 2) |
55 if (!isscalar (dim)) | |
56 error ("fftshift: dimension must be an integer scalar"); | |
57 endif | |
58 nd = ndims (V); | |
59 sz = size (V); | |
60 sz2 = ceil (sz(dim) / 2); | |
61 idx = cell (); | |
8507 | 62 for i = 1:nd |
7208 | 63 idx{i} = 1:sz(i); |
4844 | 64 endfor |
7208 | 65 idx{dim} = [sz2+1:sz(dim), 1:sz2]; |
4844 | 66 retval = V (idx{:}); |
3191 | 67 else |
4844 | 68 if (isvector (V)) |
69 x = length (V); | |
70 xx = ceil (x/2); | |
71 retval = V([xx+1:x, 1:xx]); | |
72 elseif (ismatrix (V)) | |
73 nd = ndims (V); | |
74 sz = size (V); | |
75 sz2 = ceil (sz ./ 2); | |
76 idx = cell (); | |
8507 | 77 for i = 1:nd |
4844 | 78 idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)]; |
79 endfor | |
80 retval = V (idx{:}); | |
81 else | |
82 error ("fftshift: expecting vector or matrix argument"); | |
83 endif | |
3191 | 84 endif |
85 | |
86 endfunction |