function [k,P] = spec1D(x,h,hnng,slp)

%----------------------
x = x(~isnan(h));
h = h(~isnan(h));
%----------------------

%----------------------
Nx = length(h);

if(mod(Nx,2)==1)
x  = x(1:end-1);
h  = h(1:end-1);
Nx = Nx -1;
end
%----------------------

%----------------------
Lx = x(end) - x(1);
dx = x(2)   - x(1);
%----------------------

%----------------------
k  = 2*pi * [0:Nx-1]/Lx;
k  = fftshift(k - k(end/2+1));
%----------------------

%----------------------
if(slp)
[slope,shift,hl] = lsq(x,h);
h    = h - hl';
end

h    = h - mean(h);

if(hnng)
wx   = hanning(Nx)';
h    = h .* wx;
end
%----------------------

%----------------------
hh   = fft(h)*dx;
P    = hh.*conj(hh)/Lx;

P    = fftshift(P);
k    = fftshift(k);

if(hnng) 
P    = P * (8/3); 
end
%----------------------
