
给个例子:
dt=.1
t=[0:dt:100]
x=cos(t)
[a,b]=xcorr(x,'unbiased')
plot(b*dt,a)
上面代码是求自相关函数并作图,
matlab中查看帮助时,
help xcorr 解释其意思是:
C(m) = E[A(n+m)*conj(B(n))] = E[A(n)*conj(B(n-m))];
但是,在调用xcorr函数求自相关时,有 scaleopt参数
r=xcorr(s,SCALEOPT)
SCALEOPT有
'biased' - scales the raw cross-correlation by 1/M.
'unbiased' - scales the raw correlation by 1/(M-abs(lags)).
'coeff'- normalizes the sequence so that the auto-correlations
at zero lag are identically 1.0.
'none' - no scaling (this is the default).
注意观察下面的测试:
s = [1 2 3]
r = xcorr(s)
r =
3.00008.0000 14.00008.00003.0000
当用r=xcorr(s,'unbiased')时就能得到
r =3.00004.00004.66674.00003.0000
function [f,k]=sconv(f1,f2,k1,k2,p)%计算连续信号卷积积分f(t)=f1(t)*f2(t)
%f:卷积积分f(t)对应的非零样值向量
%k:f(t)的对应时间向量
%f1:f1(t)非零样值向量
%f2:f2(t)的非零样值向量
%k1:f1(t)的对应时间向量
%k2:f2(t)的对应时间向量
%p:取样时间间隔
f=conv(f1,f2)
f=f*p
k0=k1(1)+k2(1)
k3=length(f1)+length(f2)-2
k=k0:p:k0+k3*p
subplot(2,2,1)
plot(k1,f1)
title('f1(t)')
xlabel('t')
ylabel('f1(t)')
subplot(2,2,2)
plot(k2,f2)
title('f2(t)')
subplot(2,2,3)
plot(k,f)
h=get(gca,'position')
h(3)=2.5*h(3)
set(gca,'position',h)
title('f(t)=f1(t)*f2(t)')
xlabel('t')
ylabel('f(t)')
这个程序可以实现任何情况的卷积
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)