收藏 分享(赏)

matlab求自相关.doc

上传人:kpmy5893 文档编号:7653931 上传时间:2019-05-23 格式:DOC 页数:5 大小:82KB
下载 相关 举报
matlab求自相关.doc_第1页
第1页 / 共5页
matlab求自相关.doc_第2页
第2页 / 共5页
matlab求自相关.doc_第3页
第3页 / 共5页
matlab求自相关.doc_第4页
第4页 / 共5页
matlab求自相关.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、matlab 信号处理概念;自相关函数;谱密度分析;allan1. 首先说说自相关和互相关的概念。这个是信号分析里的概念,他们分别表示的是两个时间序列之间和同一个时间序列在任意两个不同时刻的取值之间的相关程度,即互相关函数是描述随机信号 x(t),y(t)在任意两个不同时刻 t1,t2 的取值之间的相关程度,自相关函数是描述随机信号 x(t)在任意两个不同时刻 t1,t2 的取值之间的相关程度。自相关函数是描述随机信号 X(t)在任意两个不同时刻 t1,t2 的取值之间的相关程度;互相关函数给出了在频域内两个信号是否相关的一个判断指标,把两测点之间信号的互谱与各自的自谱联系了起来。它能用来确定

2、输出信号有多大程度来自输入信号,对修正测量中接入噪声源而产生的误差非常有效.事实上,在图象处理中,自相关和互相关函数的定义如下:设原函数是 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)上面代码是求自相关函数并作图,对于互相关函数,稍微修改

3、一下就可以了,即把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);su

4、bplot(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) 相关程度与相关函数的取值有什么联系?相关系数只是一个比率,不是等单位量度,无什么单位名称,也不是相关的百分数,一般取小数点后两位来表示。相关系数的正负号只表示相关的

5、方向,绝对值表示相关的程度。因为不是等单位的度量,因而不能说相关系数 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 是没

6、有将均值减掉做的相关,autocorr 则是减掉了均值。xcorrCross-correlationSyntaxc = 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(.)Descriptionxcorr estimates the cross-correlation sequence of a

7、random process. Autocorrelation is handled as a special case.The true cross-correlation sequence iswhere 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 i

8、nfinite-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 (N1). 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 vect

9、or length for inputs to xcorr is 220. 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 pro

10、duce 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 wit

11、h 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

12、the cross-correlation, where option is biased: Biased estimate of the cross-correlation function unbiased: Unbiased estimate of the cross-correlation function coeff: Normalizes the sequence so the autocorrelations at zero lag are identically 1.0. none, to use the raw, unscaled cross-correlations (de

13、fault)See 1 for more information on the properties of biased and unbiased correlation estimates.c = xcorr(x,option) specifies one of the above normalization options for the autocorrelation.c = xcorr(x,y,maxlags) returns the cross-correlation sequence over the lag range -maxlags:maxlags. Output c has

14、 length 2*maxlags+1.c = xcorr(x,maxlags) returns the autocorrelation sequence over the lag range -maxlags:maxlags. Output c has length 2*maxlags+1. If x is an N-by-P matrix, c is a matrix with 2*maxlags+1 rows whose P2 columns contain the autocorrelation sequences for all combinations of the columns

15、 of x.c = xcorr(x,y,maxlags,option) specifies both a maximum number of lags and a scaling option for the cross-correlation.c = xcorr(x,maxlags,option) specifies both a maximum number of lags and a scaling option for the autocorrelation.c,lags = xcorr(.) returns a vector of the lag indices at which c

16、 was estimated, with the range -maxlags:maxlags. When maxlags is not specified, the range of lags is -N+1:N-1.In all cases, the cross-correlation or autocorrelation computed by xcorr has the zeroth lag in the middle of the sequence, at element or row maxlags+1 (element or row N if maxlags is not spe

17、cified).ExamplesThe second output, lags, is useful for plotting the cross-correlation or autocorrelation. For example, the estimated autocorrelation of zero-mean Gaussian white noise cww(m) can be displayed for -10 m 10 using:ww = randn(1000,1);c_ww,lags = xcorr(ww,10,coeff);stem(lags,c_ww)Swapping

18、the x and y input arguments reverses (and conjugates) the output correlation sequence. For row vectors, the resulting sequences are reversed left to right; for column vectors, up and down. The following example illustrates this property (mat2str is used for a compact display of complex numbers):x =

19、1,2i,3; y = 4,5,6;c1,lags = xcorr(x,y);c1 = mat2str(c1,2), lagsc2 = conj(fliplr(xcorr(y,x);c2 = mat2str(c2,2)For the case where input argument x is a matrix, the output columns are arranged so that extracting a row and rearranging it into a square array produces the cross-correlation matrix correspo

20、nding to the lag of the chosen row. For example, the cross-correlation at zero lag can be retrieved by:randn(state,0)X = randn(2,2);M,P = size(X);c = xcorr(X);c0 = zeros(P); c0(:) = c(M,:) % Extract zero-lag rowYou can calculate the matrix of correlation coefficients that the MATLAB function corrcoef generates by substituting: c = xcov(X,coef)in the last example. The function xcov subtracts the mean and then calls xcorr.Use fftshift to move the second half of the sequence starting at the zeroth lag to the front of the sequence. fftshift swaps the first and second halves of a sequence.

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报