# Path: src/spectrum/tools.py
# def nextpow2(x):
#     """returns the smallest power of two that is greater than or equal to the
#     absolute value of x.
# 
#     This function is useful for optimizing FFT operations, which are
#     most efficient when sequence length is an exact power of two.
# 
#     :Example:
# 
#     .. doctest::
# 
#         >>> from spectrum import nextpow2
#         >>> x = [255, 256, 257]
#         >>> nextpow2(x)
#         array([8, 8, 9])
# 
#     """
#     res = ceil(log2(x))
#     return res.astype('int')  #we want integer values only but ceil gives float


from numpy.fft import fft, ifft
from .tools import nextpow2
from numpy import real
from spectrum.levinson import LEVINSON

        from scipy.signal import lfilter
        noise = randn(50000,1);  % Normalized white Gaussian noise
        x = filter([1], [1 1/2 1/3 1/4], noise)
        x = x[45904:50000]
        x.reshape(4096, 1)
        x = x[0]

    Compute the predictor coefficients, estimated signal, prediction error, and autocorrelation sequence of the prediction error:


    1.00000 + 0.00000i   0.51711 - 0.00000i   0.33908 - 0.00000i   0.24410 - 0.00000i

    ::

        a = lpc(x, 3)
        est_x = lfilter([0 -a(2:end)],1,x);    % Estimated signal
        e = x - est_x;                        % Prediction error
        [acs, lags] = xcorr(e,'coeff');   % ACS of prediction error

    """

    m = len(x)
    if N is None:
        N = m - 1 #default value if N is not provided
    elif N > m-1:
        #disp('Warning: zero-padding short input sequence')
        x.resize(N+1)
        #todo: check this zero-padding.


# Path: src/spectrum/tools.py
# def nextpow2(x):
#     """returns the smallest power of two that is greater than or equal to the
#     absolute value of x.
# 
#     This function is useful for optimizing FFT operations, which are
#     most efficient when sequence length is an exact power of two.
# 
#     :Example:
# 
#     .. doctest::
# 
#         >>> from spectrum import nextpow2
#         >>> x = [255, 256, 257]
#         >>> nextpow2(x)
#         array([8, 8, 9])
# 
#     """
#     res = ceil(log2(x))
#     return res.astype('int')  #we want integer values only but ceil gives float


# Path: src/spectrum/lpc.py
from numpy.fft import fft, ifft
from .tools import nextpow2
from numpy import real
from spectrum.levinson import LEVINSON


        from scipy.signal import lfilter
        noise = randn(50000,1);  % Normalized white Gaussian noise
        x = filter([1], [1 1/2 1/3 1/4], noise)
        x = x[45904:50000]
        x.reshape(4096, 1)
        x = x[0]

    Compute the predictor coefficients, estimated signal, prediction error, and autocorrelation sequence of the prediction error:


    1.00000 + 0.00000i   0.51711 - 0.00000i   0.33908 - 0.00000i   0.24410 - 0.00000i

    ::

        a = lpc(x, 3)
        est_x = lfilter([0 -a(2:end)],1,x);    % Estimated signal
        e = x - est_x;                        % Prediction error
        [acs, lags] = xcorr(e,'coeff');   % ACS of prediction error

    """

    m = len(x)
    if N is None:
        N = m - 1 #default value if N is not provided
    elif N > m-1:
        #disp('Warning: zero-padding short input sequence')
        x.resize(N+1)
        #todo: check this zero-padding.


    X = fft(x, 2**nextpow2(2.*len(x)-1))