3191
|
1 ## Copyright (C) 1997 by Vincent Cautaerts |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
|
17 ## usage: y = fftshift(W) |
|
18 ## |
|
19 ## Performs a shift of the vector V, for use with the "fft" and "ifft" |
|
20 ## functions, in order the move the frequency 0 to the centre of |
|
21 ## the vector or matrix. |
|
22 ## |
|
23 ## If V is a vector of E datas corresponding to E time samples spaced |
|
24 ## of Dt each, then fftshift (fft (V)) correspond to frequencies |
|
25 ## |
|
26 ## f = linspace (-E/(4*DT), (E/2-1)/(2*DT), E) |
|
27 ## |
|
28 ## If V is a matrix, does the same holds for rows and columns. |
|
29 |
|
30 ## Author: Vincent Cautaerts <vincent@comf5.comm.eng.osaka-u.ac.jp> |
|
31 ## Created: July 1997 |
|
32 ## Adapted-By: jwe |
|
33 |
|
34 function retval = fftshift (V) |
|
35 |
|
36 retval = 0; |
|
37 |
|
38 if (nargin != 1) |
|
39 usage ("usage: fftshift (X)"); |
|
40 endif |
|
41 |
|
42 if (is_vector (V)) |
|
43 x = length (V); |
|
44 xx = ceil (x/2); |
|
45 retval = V([xx+1:x, 1:xx]); |
|
46 elseif (is_matrix (V)) |
|
47 [x, y] = size (V); |
|
48 xx = ceil (x/2); |
|
49 yy = ceil (y/2); |
|
50 retval = V([xx+1:x, 1:xx], [yy+1:y, 1:yy]); |
|
51 else |
|
52 error ("fftshift: expecting vector or matrix argument"); |
|
53 endif |
|
54 |
|
55 endfunction |