% Converts column vector in time domain to vector in frequency domain.
%    using the real Fourier components discussed in the text
% Let X = < x[1] ... x[n] >
% Let F = dft(X)
% Then X[i] = F[1] + F[2] cos(pi i/N) + F[3] sin(pi i/N) +
%       ... F[N-2] cos(pi (N-1)/N) +F[N-1] sin(pi i (N-1)/N)) + F[N] cos(pi i).

% dft(x) is equal to trigBasis(N/2)\x but computes faster, since it uses 
% the FFT.
 
function f = dft(x)
   n = size(x);
   n = n(1);
   y(1,1) = x(n,1);
   y(2:n,1) = x(1:n-1,1);% Rotate x to change from 1 based indexing to 0 based
   g = ifft(y);
   f(1,1)=g(1,1);
   k = floor(n/2);
   for j=1:k-1
     f(2*j,1) = g(j+1,1) + g(n+1-j); 
     f(2*j+1,1) = (g(j+1,1) - g(n+1-j))/i; 
   f(n,1)=g(k+1,1);
   end
end
