Mercurial > hg > octave-lyh
annotate scripts/signal/fftshift.m @ 11529:f98f925d8e5c
Add undocumented function erfcx to documentation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 14 Jan 2011 11:59:59 -0800 |
parents | fd0a3ac60b0e |
children | c792872f8942 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1997-2011 Vincent Cautaerts |
3426 | 2 ## |
3922 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3191 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3191 | 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/>. | |
3191 | 18 |
3449 | 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} {} fftshift (@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} {} fftshift (@var{x}, @var{dim}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
22 ## Perform a shift of the vector @var{x}, for use with the @code{fft} |
3449 | 23 ## and @code{ifft} functions, in order the move the frequency 0 to the |
3499 | 24 ## center of the vector or matrix. |
3191 | 25 ## |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
26 ## If @var{x} is a vector of @math{N} elements corresponding to @math{N} |
3499 | 27 ## time samples spaced of @math{Dt} each, then @code{fftshift (fft |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
28 ## (@var{x}))} corresponds to frequencies |
3191 | 29 ## |
3449 | 30 ## @example |
4077 | 31 ## f = ((1:N) - ceil(N/2)) / N / Dt |
3449 | 32 ## @end example |
3191 | 33 ## |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
34 ## If @var{x} is a matrix, the same holds for rows and columns. If |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
35 ## @var{x} is an array, then the same holds along each dimension. |
4844 | 36 ## |
37 ## The optional @var{dim} argument can be used to limit the dimension | |
38 ## along which the permutation occurs. | |
3449 | 39 ## @end deftypefn |
3191 | 40 |
41 ## Author: Vincent Cautaerts <vincent@comf5.comm.eng.osaka-u.ac.jp> | |
42 ## Created: July 1997 | |
43 ## Adapted-By: jwe | |
44 | |
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 function retval = fftshift (x, dim) |
3191 | 46 |
47 retval = 0; | |
48 | |
4844 | 49 if (nargin != 1 && nargin != 2) |
6046 | 50 print_usage (); |
3191 | 51 endif |
52 | |
4844 | 53 if (nargin == 2) |
54 if (!isscalar (dim)) | |
55 error ("fftshift: dimension must be an integer scalar"); | |
56 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
|
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); |
4844 | 59 sz2 = ceil (sz(dim) / 2); |
60 idx = cell (); | |
8507 | 61 for i = 1:nd |
7208 | 62 idx{i} = 1:sz(i); |
4844 | 63 endfor |
7208 | 64 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
|
65 retval = x(idx{:}); |
3191 | 66 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
|
67 if (isvector (x)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
68 x = length (x); |
4844 | 69 xx = ceil (x/2); |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
70 retval = x([xx+1:x, 1:xx]); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
71 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
|
72 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
|
73 sz = size (x); |
4844 | 74 sz2 = ceil (sz ./ 2); |
75 idx = cell (); | |
8507 | 76 for i = 1:nd |
4844 | 77 idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)]; |
78 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
|
79 retval = x(idx{:}); |
4844 | 80 else |
81 error ("fftshift: expecting vector or matrix argument"); | |
82 endif | |
3191 | 83 endif |
84 | |
85 endfunction |