function retval = FFTsort(p)
% usage: ndx = FFTsort(p)
% description: given positive integer p as input,
% returns an index vector of length N = 2^p
% suitable for implementing the FFT, with
% indexing starting at 1.
 
if (p == 2)
  retval = [1 3 2 4]
elseif (p == 3)
  retval = [1 5 3 7 2 6 4 8];
else
  error('p not defined')
end
