【 MATLAB 】Filter Data

Filter Data

Filter Difference Equation(滤波器差分方程)

滤波器是一种数据处理技术,可以消除数据中的高频波动或从数据中去除特定频率的周期性趋势。

在MATLAB®中,滤波器功能根据以下差分方程过滤数据x的向量,该差分方程描述了抽头延迟线滤波器。

【 MATLAB 】Filter Data

在该等式中,a和b是滤波器系数的矢量,Na是反馈滤波器阶数,Nb是前馈滤波器阶数。 n是x的当前元素的索引。 输出y(n)是x和y的当前元素和先前元素的线性组合。

滤波函数使用指定的系数向量a和b来过滤输入数据x。 



Moving-Average Filter of Traffic Data


滤波器功能是实现移动平均滤波器的一种方法,这是一种常见的数据平滑技术。
The following difference equation describes a filter that averages time-dependent data with respect to the current hour and the three previous hours of data.

(以下差分方程描述了一个过滤器,它根据当前小时和前三个小时的数据平均时间相关数据。)

【 MATLAB 】Filter Data

导入描述流量随时间变化的数据,并将第一列车辆计数分配给向量x。

clc
clear
close all

% Import data that describes traffic flow over time, and assign the first column of vehicle counts to the vector x.
load count.dat
x = count(:,1);

% Create the filter coefficient vectors.
a = 1;
b = [1/4 1/4 1/4 1/4];

% Compute the 4-hour moving average of the data, and plot both the original data and the filtered data.
y = filter(b,a,x);

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

【 MATLAB 】Filter Data


Modify Amplitude of Data


This example shows how to modify the amplitude of a vector of data by applying a transfer function.
In digital signal processing, filters are often represented by a transfer function. The Z-transform of the difference equation

此示例显示如何通过应用传递函数来修改数据矢量的幅度。
在数字信号处理中,滤波器通常由传递函数表示。 差分方程的Z变换

【 MATLAB 】Filter Data

is the following transfer function.

【 MATLAB 】Filter Data

Use the transfer function

【 MATLAB 】Filter Data

to modify the amplitude of the data in count.dat.

clc
clear
close all

% Load the data and assign the first column to the vector x.
load count.dat
x = count(:,1);

% Create the filter coefficient vectors according to the transfer function .
a = [1 0.2];
b = [2 3];

% Compute the filtered data, and plot both the original data and the filtered data. This filter primarily modifies the amplitude of the original data.
y = filter(b,a,x);

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

【 MATLAB 】Filter Data