pythonmatrixlpcautocorrelation

autocorrelation matrix with order in Python


I have a equation of autocorrelation matrix with lag needed for lpc analysis:

(click to download image): r_{l}(m) =\sum_{n=0}^{N-1-m}{\overline{x}_{l}(n)\overline{x}_{l}(n+m)}, m=0,1,...p

I wrote methods:

def autocorr_matrix(x,order):
    R = numpy.zeros((order, order))
    for i in range(0,order):
        for j in range(0,order):
            R[i,j] = autocorrelate(x, abs(i-j))
    return R
def autocorrelate(x,lag):
    return numpy.correlate(x[0:len(x)-lag],x[lag:len(x)])

is it correct solution? Anybody have idea how can i test results of these methods?


Solution

  • To test your results you can use two methods:

    1- Create two sin signals with phase shift and see whether your code can measure the correlation or not.

    2- Use some trustable libraries for correlation and check your results. the library I'm using is 'statsmodel': statsmodel.org

    from statsmodels.tsa.stattools import acf,ccf
    

    acf is for autocorrelation and ccf is for cross-correlation.