Estimate Autocorrelation using Python

后端 未结 5 1103
庸人自扰
庸人自扰 2020-12-02 07:34

I would like to perform Autocorrelation on the signal shown below. The time between two consecutive points is 2.5ms (or a repetition rate of 400Hz).

5条回答
  •  心在旅途
    2020-12-02 08:05

    I took a part of code from pandas autocorrelation_plot() function. I checked the answers with R and the values are matching exactly.

    import numpy
    def acf(series):
        n = len(series)
        data = numpy.asarray(series)
        mean = numpy.mean(data)
        c0 = numpy.sum((data - mean) ** 2) / float(n)
    
        def r(h):
            acf_lag = ((data[:n - h] - mean) * (data[h:] - mean)).sum() / float(n) / c0
            return round(acf_lag, 3)
        x = numpy.arange(n) # Avoiding lag 0 calculation
        acf_coeffs = map(r, x)
        return acf_coeffs
    

提交回复
热议问题