滤波数据

滤波器差分方程

`filter` 函数使用指定的系数向量 a 和 b 对输入数据 x 进行滤波。有关描述滤波器的差分方程的详细信息，请参阅 [1]

交通流量数据的移动平均值滤波器

`filter` 函数是实现移动平均值滤波器的一种方式，它是一种常见的数据平滑技术。

`$y\left(n\right)=\frac{1}{4}x\left(n\right)+\frac{1}{4}x\left(n-1\right)+\frac{1}{4}x\left(n-2\right)+\frac{1}{4}x\left(n-3\right)$`

```load count.dat x = count(:,1);```

```a = 1; b = [1/4 1/4 1/4 1/4];```

```y = filter(b,a,x); t = 1:length(x); plot(t,x,'--',t,y,'-') legend('Original Data','Filtered Data')```

修改数据振幅

`$\begin{array}{rcl}a\left(1\right)y\left(n\right)& =& b\left(1\right)x\left(n\right)+b\left(2\right)x\left(n-1\right)+...+b\left({N}_{b}\right)x\left(n-{N}_{b}+1\right)\\ & & -a\left(2\right)y\left(n-1\right)-...-a\left({N}_{a}\right)y\left(n-{N}_{a}+1\right)\end{array}$`

`$Y\left(z\right)=H\left({z}^{-1}\right)X\left(z\right)=\frac{b\left(1\right)+b\left(2\right){z}^{-1}+...+b\left({N}_{b}\right){z}^{-{N}_{b}+1}}{a\left(1\right)+a\left(2\right){z}^{-1}+...+a\left({N}_{a}\right){z}^{-{N}_{a}+1}}X\left(z\right)$`

`$H\left({z}^{-1}\right)=\frac{b\left({z}^{-1}\right)}{a\left({z}^{-1}\right)}=\frac{2+3{z}^{-1}}{1+0.2{z}^{-1}}$`

```load count.dat x = count(:,1);```

```a = [1 0.2]; b = [2 3];```

```y = filter(b,a,x); t = 1:length(x); plot(t,x,'--',t,y,'-') legend('Original Data','Filtered Data')```

参考

[1] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1999.