forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfftc.m
63 lines (53 loc) · 1.74 KB
/
fftc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function out = fftc( in, varargin )
% out = fftc( in, n, dim] ) or out = fftc( in, dim] )
%
% Compute the centered fft
%
% Inputs:
% in - an array (of any number of dimensions)
%
% Optional Inputs:
% n - zero pads to this number of elements and then perform an fft
% if a two dimensional fft, the zero pads to size [n(1) n(2)] and performs fft
% dim - if supplied, only does an fft along this dimension
% unitary - if true, use a scaling factor to make the transform unitary
%
% Written by Nicholas Dwork, Copyright 2019
%
% https://github.com/ndwork/dworkLib.git
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
p = inputParser;
p.addOptional( 'n', [], @(x) numel(x) == 0 || ispositive(x) );
p.addOptional( 'dim', [], @isnumeric );
p.parse( varargin{:} );
dim = p.Results.dim;
n = p.Results.n;
if numel( dim ) == 0 && numel( n ) ~= 0
dim = n; n=[];
end
if numel( dim ) > 0
if numel( n ) > 1, error( 'Too many elements in n with dimension supplied' ); end
out = fftshift( fft( in, n, dim ), dim );
else
switch ndims( in )
case 1
out = fftshift( fft( in, n ) );
case 2
if numel( n ) > 0
if numel( n ) ~= 2, error( 'n has the wrong number of elements' ); end
out = fftshift( fft2( in, n(1), n(2) ) );
else
out = fftshift( fft2( in ) );
end
otherwise
if numel( n ) ~= 0 && numel( n ) ~= ndims( in )
error( 'n has the wrong number of elements' );
end
out = fftshift( fftn( in, n ) );
end
end
end