matlab求自相关 下载本文

内容发布更新时间 : 2024/5/23 22:13:38星期一 下面是文章的全部内容请认真阅读。

matlab信号处理概念;自相关函数;谱密度分析;allan

1. 首先说说自相关和互相关的概念。

这个是信号分析里的概念,他们分别表示的是两个时间序列之间和同一个时间序列在任意两个不同时刻的取值之间的相关程度,即互相关函数是描述随机信号 x(t),y(t)在任意两个不同时刻t1,t2的取值之间的相关程度,自相关函数是描述随机信号x(t)在任意两个不同时刻t1,t2的取值之间的相关程度。

自相关函数是描述随机信号X(t)在任意两个不同时刻t1,t2的取值之间的相关程度;互相关函数给出了在频域内两个信号是否相关的一个判断指标,把两测点之间信号的互谱与各自的自谱联系了起来。它能用来确定输出信号有多大程度来自输入信号,对修正测量中接入噪声源而产生的误差非常有效.

事实上,在图象处理中,自相关和互相关函数的定义如下:设原函数是f(t),则自相关函数定义为R(u)=f(t)*f(-t),其中*表示卷积;设两个函数分别是f(t)和g(t),则互相关函数定义为R(u)=f(t)*g(-t),它反映的是两个函数在不同的相对位置上互相匹配的程度。 那么,如何在matlab中实现这两个相关并用图像显示出来呢? dt=.1; t=[0:dt:100]; x=cos(t);

[a,b]=xcorr(x,'unbiased'); plot(b*dt,a)

上面代码是求自相关函数并作图,对于互相关函数,稍微修改一下就可以了,即把 [a,b]=xcorr(x,'unbiased');改为[a,b]=xcorr(x,y,'unbiased');便可。 2. 实现过程:

在Matalb中,求解xcorr的过程事实上是利用Fourier变换中的卷积定理进行的,即R(u)=ifft(fft(f)×fft(g)),其中×表示乘法,注:此公式仅表示形式计算,并非实际计算所用的公式。当然也可以直接采用卷积进行计算,但是结果会与xcorr的不同。事实上,两者既然有定理保证,那么结果一定是相同的,只是没有用对公式而已。下面是检验两者结果相同的代码: dt=.1; t=[0:dt:100]; x=3*sin(t); y=cos(3*t); subplot(3,1,1); plot(t,x); subplot(3,1,2); plot(t,y); [a,b]=xcorr(x,y); subplot(3,1,3); plot(b*dt,a);

yy=cos(3*fliplr(t)); % or use: yy=fliplr(y); z=conv(x,yy); pause; subplot(3,1,3); plot(b*dt,z,'r');

即在xcorr中不使用scaling。 3. 其他相关问题:

1) 相关程度与相关函数的取值有什么联系?

相关系数只是一个比率,不是等单位量度,无什么单位名称,也不是相关的百分数,一般取小数点后两位来表示。相关系数的正负号只表示相关的方向,绝对值表示相关的程度。因为不是等单位的度量,因而不能说相关系数0.7是0.35两倍,只能说相关系数为0.7的二列变量相关程度比相关系数为0.35的二列变量相关程度更为密切和更高。也不能说相关系数从0.70到0.80与相关系数从0.30到0.40增加的程度一样大。 对于相关系数的大小所表示的意义目前在统计学界尚不一致,但通常按下是这样认为的: 相关系数 相关程度 0.00-±0.30 微相关 ±0.30-±0.50 实相关 ±0.50-±0.80 显著相关 ±0.80-±1.00 高度相关

matlab计算自相关函数autocorr和xcorr有什么不一样的?xcorr是没有将均值减掉做的相关,autocorr则是减掉了均值。

xcorr

Cross-correlation

Syntax

c = xcorr(x,y) c = xcorr(x)

c = xcorr(x,y,'option') c = xcorr(x,'option') c = xcorr(x,y,maxlags) c = xcorr(x,maxlags)

c = xcorr(x,y,maxlags,'option') c = xcorr(x,maxlags,'option') [c,lags] = xcorr(...)

Description

xcorr estimates the cross-correlation sequence of a random process. Autocorrelation is handled as a special case. The true cross-correlation sequence is

where xn and yn are jointly stationary random processes, , and E {·} is the expected value operator. xcorr must estimate the sequence

because, in practice, only a finite segment of one realization of the infinite-length random process is available.

c = xcorr(x,y) returns the cross-correlation sequence in a length 2*N-1 vector, where x and y are length N vectors (N>1). If x and y are not the same length, the shorter vector is zero-padded to the length of the longer vector.

Note The maximum allowable vector length for inputs to xcorr is 2^20. If you need to process longer sequences, see dfilt.fftfir. By default, xcorr computes raw correlations with no normalization.

The output vector c has elements given by c(m) = Rxy(m-N), m=1, ..., 2N-1.

In general, the correlation function requires normalization to produce an accurate estimate (see below).

c = xcorr(x) is the autocorrelation sequence for the vector x. If x is an N-by-P matrix, c is a matrix with 2N-1 rows whose P2 columns contain the cross-correlation sequences for all combinations of the columns of x. For more information on matrix processing with xcorr, see Multiple Channels.

xcorr produces correlations identically equal to 1.0 at zero lag only when you perform an autocorrelation and only when you set the 'coeff' option. For example,

x=0:0.01:10; X = sin(x);

[r,lags]=xcorr(X,'coeff'); max(r)

c = xcorr(x,y,'option') specifies a normalization option for the cross-correlation, where 'option' is

?

'biased': Biased estimate of the cross-correlation function

?

'unbiased': Unbiased estimate of the cross-correlation function