% Converts column vector in frequency domain to vector in time domain.
% using the real Fourier components discussed in the text
% Let X = < x[1] ... x[n] >
% Let F = idft(X)
% Then F[i] = X[1] + X[2] cos(pi i/N) + X[3] sin(pi i/N) +
% ... X[N-2] cos(pi (N-1)/N) +X[N-1] sin(pi i (N-1)/N)) + X[N] cos(pi i).
% idft(x) is equal to trigBasis(N/2)*x but computes faster, since it uses
% the FFT.
function f = idft(x)
n = size(x);
n = n(1);
k = floor(n/2);
y(1,1)=x(1,1);
for j=1:k-1
y(j+1,1) = (x(2*j,1) + i * x(2*j+1,1))/2;
y(n+1-j,1) = (x(2*j,1) - i * x(2*j+1,1))/2;
end;
y(k+1,1) = x(n,1);
g = fft(y);
f(n,1) = g(1,1);
f(1:n-1,1) = g(2:n,1); % Rotate g to change from 0 based indexging to 1 based
end