function [ Ph,fh ] = dbhilbert( t,h,fmax,npt)
%returns normalized spectral power (Ph) and corresponding frequencies (fh)
% from a Hilbert transformation of a time
% series; t is the time vector, h is the data vector, fmax is the upper
% frequency limit for plotting purposes and npts controls the zero padding 
% -- npts should be a power of 2, like 2^14 
%   
%
% first do the hilbert transformation

% hilbert transform of the data
hil=imag(hilbert(h)); %


 
hil=abs(hil); % absolute values of the hilbert transform

xp=findpeaks(hil);  %find the x-axis values corresponding to peaks values of the previous vector


tp=t(xp);  %finds the ages that correspond to the peaks
yp=hil(xp);  %find the y-axis values of the peaks



%interpolation to evenly spaced ages
ah=linspace(min(tp),max(tp),4*length(tp));
hh=interp1(tp,yp,ah); 


% XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% then we do a FFT of the Hilbert transform

% XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



[ Ph,fh ] = dbfft( ah,hh,fmax,npt);

end

