
function x = igdft(X,a,b)
% IGDFT Inverse generalized discrete fourier transform
%   X = igdft(x,a,b)
%
%   The case of a=b=0 corresponds to dft
%   The case of a=1/2, b=0 corresponds to ofdft (aka odft)
%
%   X: input signal, follows fft interface of frame per column
%   a: shift in frequency (usually 0 or 1/2)
%   b: shift in time (usually 0 or 1/2)
%   x: igdft of X
%
%   Notes: This is the normalized igdft unlike the fft-ifft definition
%          in Matlab. This means that Parsevals theorem doesn't need
%          division by K

% ------- igdft.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 Inverse Odd Frequency DFT
if nargin < 2; a = 1/2; end
if nargin < 3; b = 0;   end

% Argument check
if a<0 | a>1; error('Shift in frequency must be between 0 and 1 (inclusive)'); end
if b<0 | b>1; error('Shift in time must be between 0 and 1 (inclusive)');      end

% Get size of input signal
[K,fnum] = size(X);

% Pre weights (in frequency)
kw = exp(j*2*pi*([0:K-1]+a)*b/K);
kw = diag(sparse(kw));

% Post weights (in time)
nw = exp(j*2*pi*a*[0:K-1]/K);
nw = diag(sparse(nw));

% So the igdft is simply
x = sqrt(K)*full(nw*ifft(full(kw*X)));
