
function T = gdftmtx(N,a,b,symv)
% GDFTMTX Generalized discrete fourier transform matrix
%   T = gdftmtx(N,a,b,symv)
%
%   The case of a=b=0 corresponds to dft
%   The case of a=1/2, b=0 corresponds to ofdft (aka odft)
%
%   Notes: All the matrices are unitary so the inverse is
%          simply the hermitian transpose or in MATLAB
%          T * T' = I
%
%   N:    transform size (NxN)
%   a:    shift in frequency (usually 0 or 1/2)
%   b:    shift in time (usually 0 or 1/2)
%   symv: if this flag is set then a symbolic matrix is produced
%         used for various proofs

% ------- gdftmtx.m ----------------------------------------
% Marios Athineos, marios@ee.columbia.edu
% http://www.ee.columbia.edu/~marios/
% Copyright (c) 2004-2005 by Columbia University.
% All rights reserved.
% ----------------------------------------------------------

% The default is the regular DFT
if nargin < 2; a    = 0; end
if nargin < 3; b    = 0; end
if nargin < 4; symv = 0; end
    
% For faster execution I am generating indices using
% outer products instead of ndgrid
n = (0:N-1)';

% If the flag is set convert stuff to
% symbolic and we are all set
if symv
    N = sym(N);
    n = sym(n);
end

% So the transformation matrix is simply
T = sqrt(1/N) *exp(-j *2*pi *(n+a) *(n+b)' /N);

