相关疑难解决方法(0)

使用Python估计自相关

我想对下面显示的信号执行自相关.两个连续点之间的时间是2.5ms(或400Hz的重复率).

在此输入图像描述

这是我想要使用的估计自相关的等式(取自http://en.wikipedia.org/wiki/Autocorrelation,部分估计):

在此输入图像描述

在python中查找我的数据估计自相关的最简单方法是什么?有什么类似于numpy.correlate我可以使用的东西吗?

或者我应该只计算均值和方差?


编辑:

unutbu的帮助,我写道:

from numpy import *
import numpy as N
import pylab as P

fn = 'data.txt'
x = loadtxt(fn,unpack=True,usecols=[1])
time = loadtxt(fn,unpack=True,usecols=[0]) 

def estimated_autocorrelation(x):
    n = len(x)
    variance = x.var()
    x = x-x.mean()
    r = N.correlate(x, x, mode = 'full')[-n:]
    #assert N.allclose(r, N.array([(x[:n-k]*x[-(n-k):]).sum() for k in range(n)]))
    result = r/(variance*(N.arange(n, 0, -1)))
    return result

P.plot(time,estimated_autocorrelation(x))
P.xlabel('time (s)')
P.ylabel('autocorrelation')
P.show()
Run Code Online (Sandbox Code Playgroud)

python signal-processing numpy

29
推荐指数
4
解决办法
5万
查看次数

如何在数据中找到周期?

我有一个数据集(一个数组),我需要在其中找到周期性.我该怎么办?有人说我可以使用FFT,但我不确定它会如何给我周期性.非常感谢您的帮助!

algorithm fft c#-3.0

17
推荐指数
3
解决办法
1万
查看次数

是否有任何具有标准化输出的numpy autocorrelation功能?

我遵循了另一篇文章中定义自相关函数的建议:

def autocorr(x):
    result = np.correlate(x, x, mode = 'full')
    maxcorr = np.argmax(result)
    #print 'maximum = ', result[maxcorr]
    result = result / result[maxcorr]     # <=== normalization

    return result[result.size/2:]
Run Code Online (Sandbox Code Playgroud)

但最大值不是"1.0".因此我引入了标有"<=== normalization"的行

我尝试了使用"时间序列分析"(Box - Jenkins)第2章数据集的函数.我希望得到像图的结果.那本书中的2.7.但是我得到了以下内容:

在此输入图像描述

任何人都有这种奇怪的不期望的自相关行为的解释?

增加(2012-09-07):

我进入Python - 编程并执行以下操作:

from ClimateUtilities import *
import phys

#
# the above imports are from R.T.Pierrehumbert's book "principles of planetary 
# climate" 
# and the homepage of that book at "cambridge University press" ... they mostly  
# define   the
# class "Curve()" used in …
Run Code Online (Sandbox Code Playgroud)

python statistics numpy correlation autocorrelation

9
推荐指数
2
解决办法
1万
查看次数

查找算法信号中的周期性

在测试关于以下递归关系的猜想

在此输入图像描述 ,

为数字序列声称某种类型的周期性,我写了一个python程序,它计算序列并将它们打印在一个表中.

 1   # Consider the recursive relation x_{i+1} = p-1 - (p*i-1 mod x_i)
 2   # with p prime and x_0 = 1. What is the shortest period of the
 3   # sequence?
 4   
 5   from __future__ import print_function
 6   import numpy as np
 7   from matplotlib import pyplot  as plt
 8   
 9   # The length of the sequences.
 10  seq_length = 100
 11  
 12  upperbound_primes = 30
 13  
 14  # Computing a list of prime numbers up …
Run Code Online (Sandbox Code Playgroud)

python signal-processing periodic-task

7
推荐指数
1
解决办法
4612
查看次数