转载:http://blog.sina.com.cn/s/blog_7086379501012pd1.html
这是一个采用三点滑动平均算法的程序:
R=51;
d=0.8*(rand(R,1)-0.5);%随机波动
m=0:R-1;
s=2*m.*(0.9.^m);%原信号s=2*x*0.9^x
x=s+d'; %x=s+d
subplot(2,1,1);
plot(m,d','r-',m,s,'g--',m,x,'d-,');%
legend('d[n]','s[n]','x[n]');
x1=[0 0 x];x2=[0 x 0];x3=[x 0 0]; %三点平均器
y=(x1+x2+x3)/3;
subplot(2,1,2);
plot(m,y(2:R+1),'r-',m,s,'g--');
legend('y[n]','s[n]');
其中的x1=[0 0 x];x2=[0 x 0];x3=[x 0 0];这句不是很明白,这不是应该定义的是三个矩阵吗?
为什么这句可以实现y(n)=1/3*(x[n-1]+x[n]+x[n+1])???
如果x=[x(1),x(2),...,x(n)],则按定义:
x1=[0 0 x];x2=[0 x 0];x3=[x 0 0];
有
x1=[0,0,x(1),x(2),...,x(n)]
x2=[0,x(1),x(2),...,x(n),0]
x3=[x(1),x(2),...,x(n),0,0]
把这3个数组对齐相加,y有
y=[0*0+x(1), 0+x(1)+x(2), x(1)+x(2)+x(3),..., x(N-1)+x(N)+0, x(N)+0+0]/3
取其中2:N+1个元素,就是y(n)=1/3*(x[n-1]+x[n]+x[n+1])。
由于y(1)的n-1不存在,用0代替;y(N)的n+1不存在,也用0代替了。