-
Notifications
You must be signed in to change notification settings - Fork 29
/
opDFT2.m
112 lines (95 loc) · 3.81 KB
/
opDFT2.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
classdef opDFT2 < opOrthogonal
%OPDFT2 Two-dimensional fast Fourier transform (DFT).
%
% opDFT2(M,N) creates a two-dimensional normalized Fourier transform
% operator for matrices of size M by N. Input and output of the
% matrices is done in vectorized form.
%
% opDFT2(M,N,CENTERED) just like opDFT2(M,N), but with components
% shifted to have to zero-frequency component in the center of the
% spectrum, if the CENTERED flag is set to true.
% Copyright 2009, Ewout van den Berg and Michael P. Friedlander
% See the file COPYING.txt for full copyright information.
% Use the command 'spot.gpl' to locate this file.
% http://www.cs.ubc.ca/labs/scl/spot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Properties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
properties ( Access = private )
funHandle % Multiplication function
end % properties
properties ( SetAccess = private, GetAccess = public )
inputdims % Dimensions of the input
centered % Flag if operator created with center flag
end % properties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - Public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% opDFT2. Constructor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function op = opDFT2(m,n,centered)
if nargin < 1 || nargin > 3
error('Invalid number of arguments to opDFT2.');
elseif nargin == 1
n = m;
end
if nargin >= 3 && islogical(centered)
centered = true;
else
centered = false;
end
if ~isscalar(m) || m~=round(m) || m <= 0
error('First argument to opDFT2 must be positive integer.');
end
if ~isscalar(n) || n~=round(n) || n <= 0
error('Second argument to opDFT2 must be positive integer.');
end
op = op@opOrthogonal('DFT2',m*n,m*n);
op.centered = centered;
op.cflag = true;
op.inputdims = [m,n];
% Initialize function handle
if centered
op.funHandle = @opDFT2d_centered_intrnl;
else
op.funHandle = @opDFT2d_intrnl;
end
end % function opDFT2
end % methods - public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - protected
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods( Access = protected )
function y = multiply(op,x,mode)
y = op.funHandle(op,x,mode);
end % function multiply
end % methods - protected
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - private
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods( Access = private )
function y = opDFT2d_intrnl(op,x,mode)
m = op.inputdims(1);
n = op.inputdims(2);
if mode == 1
y = reshape( fft2(reshape(full(x),m,n)) / sqrt(m*n), m*n, 1);
else
y = reshape(ifft2(reshape(full(x),m,n)) * sqrt(m*n), m*n, 1);
end
end % function opDFT2d_intrnl
% Two-dimensional DFT - Centered
function y = opDFT2d_centered_intrnl(op,x,mode)
m = op.inputdims(1);
n = op.inputdims(2);
if mode == 1
y = fftshift(fft2(reshape(full(x),m,n))) / sqrt(m*n);
y = reshape(y,m*n,1);
else
y = ifft2(ifftshift(reshape(full(x),m,n))) * sqrt(m*n);
y = reshape(y,m*n,1);
end
end % function opDFT2d_centered_intrnl
end % methods - private
end % classdef