forked from mpf/spot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opDFT.m
106 lines (88 loc) · 3.19 KB
/
opDFT.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
classdef opDFT < opOrthogonal
%OPDFT Fast Fourier transform (DFT).
%
% opDFT(M) create a unitary one-dimensional discrete Fourier
% transform (DFT) for vectors of length M.
%
% opDFT(M,CENTERED), with the CENTERED flag set to true, creates a
% unitary DFT that shifts the zero-frequency component to the center
% of the spectrum.
% 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 )
centered
end % properties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% opDFT. Constructor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function op = opDFT(m,centered)
if nargin < 1 || nargin > 2
error('Invalid number of arguments to opDFT.');
end
if nargin == 2 && islogical(centered)
centered = true;
else
centered = false;
end
if ~isscalar(m) || m~=round(m) || m <= 0
error('First argument to opDFT has to be a positive integer.');
end
op = op@opOrthogonal('DFT',m,m);
op.centered = centered;
op.cflag = true;
op.sweepflag = true;
% Create function handle
if centered
op.funHandle = @opDFT_centered_intrnl;
else
op.funHandle = @opDFT_intrnl;
end
end % function opDFT
end % methods - public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - protected
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods( Access = protected )
% Multiplication
function y = multiply(op,x,mode)
y = op.funHandle(op,x,mode);
end % Multiply
end % Methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - private
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods( Access = private )
function y = opDFT_intrnl(op,x,mode)
% One-dimensional DFT
n = op.n;
if mode == 1
% Analysis
y = fft(full(x)) / sqrt(n);
else
% Synthesis
y = ifft(full(x)) * sqrt(n);
end
end
function y = opDFT_centered_intrnl(op,x,mode)
% One-dimensional DFT - Centered
n = op.n;
if mode == 1
y = fftshift(fft(full(x))) / sqrt(n);
else
y = ifft(ifftshift(full(x))) * sqrt(n);
end
end
end % Methods
end % classdef