% this takes a vector u and returns k and amp.  k is the vector of
% wave-numbers, amp is the logarithm (base 10) of the fourier
% amplitudes.  If u comes from sampling a function with a uniform mesh,
% the the function is resolved if the highest amplitudes are at the
% level of round-off error.  (amp between -14 and -16).  
%
% [k,amp] = find_spec(u)

function [k,amp] = find_spec(u)

N = length(u);

v = fft(u);

for kk=0:floor((N-1)/2)
  if kk == 0 
    amp(kk+1) = log10(sqrt(v(1+kk)^2)/N + 10e-16);
  else
    amp(kk+1) = log10(sqrt(v(1+kk)*v(N-kk+1))/N + 1e-16);    
  end
  k(kk+1) = kk;
end
