找回密码
 注册
关于网站域名变更的通知
查看: 493|回复: 1
打印 上一主题 下一主题

MATLAB之filter 函数介绍(一维数字滤波器)

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-8-3 13:33 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
本帖最后由 mytomorrow 于 2020-8-3 14:33 编辑 # ~5 ]& F; |3 W$ y

) z. e- n& ]; |6 H. g  E0 [

了解这个函数,先看看这个基础知识:介绍一下MATLAB 的Rational Transfer Function(有理传递函数)

filter

1-D digital filter

Syntax

y = filter(b,a,x)

y = filter(b,a,x,zi)

y = filter(b,a,x,zi,dim)

[y,zf] = filter(___)

Description

y = filter(b,a,x) 使用由分子和分母系数 b 和 a 定义的有理传递函数对输入数据 x 进行滤波。

If a(1) is not equal to 1, then filter normalizes the filter coefficients by a(1). Therefore, a(1) must be nonzero.

  • If x is a vector, then filter returns the filtered data as a vector of the same size as x.

  • If x is a matrix, then filter acts along the first dimension and returns the filtered data for each column.

  • If x is a multidimensional array, then filter acts along the first array dimension whose size does not equal 1.

    / _; o  C0 n& n* E0 `% O

针对这条语法举个例子:

Moving-Average Filter

移动平均滤波器是用于平滑噪声数据的常用方法。 此示例使用过滤器函数计算沿数据向量的平均值。

Create a 1-by-100 row vector of sinusoidal data that is corrupted by random noise.

t = linspace(-pi,pi,100);rng default  %initialize random number generatorx = sin(t) + 0.25*rand(size(t));

A moving-average filter slides a window of length windowSize along the data, computing averages of the data contained in each window. The following difference equation defines a moving-average filter of a vector:

For a window size of 5, compute the numerator and denominator coefficients for the rational transfer function.

对于窗口大小为5,计算有理传递函数的分子和分母系数。

windowSize = 5; b = (1/windowSize)*ones(1,windowSize);a = 1;

Find the moving average of the data and plot it against the original data.

找到数据的移动平均值并根据原始数据绘制它。

y = filter(b,a,x);plot(t,x)hold onplot(t,y)legend('Input Data','Filtered Data')



# {; n2 Z4 {( I' L* t1 P' H/ L

y = filter(b,a,x,zi) uses initial conditions zi for the filter delays. The length of zi must equal max(length(a),length(b))-1.

举例说明:

Filter Data in Sections

Use initial and final conditions for filter delays to filter data in sections, especially if memory limitations are a consideration.

Generate a large random data sequence and split it into two segments, x1 and x2.

x = randn(10000,1);x1 = x(1:5000);x2 = x(5001:end);

The whole sequence, x, is the vertical concatenation of x1 and x2.

Define the numerator and denominator coefficients for the rational transfer function,

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

Filter the subsequences x1 and x2 one at a time. Output the final conditions from filtering x1 to store the internal status of the filter at the end of the first segment.

[y1,zf] = filter(b,a,x1);

Use the final conditions from filtering x1 as initial conditions to filter the second segment, x2.

y2 = filter(b,a,x2,zf);

y1 is the filtered data from x1, and y2 is the filtered data from x2. The entire filtered sequence is the vertical concatenation of y1 and y2.

Filter the entire sequence simultaneously for comparison.

y = filter(b,a,x);isequal(y,[y1;y2])ans = logical   1

y = filter(b,a,x,zi,dim) acts along dimension dim. For example, if x is a matrix, then filter(b,a,x,zi,2) returns the filtered data for each row.

举例:

This example filters a matrix of data with the following rational transfer function.

Create a 2-by-15 matrix of random input data.

rng default  %initialize random number generatorx = rand(2,15);

Define the numerator and denominator coefficients for the rational transfer function.

b = 1;a = [1 -0.2];

Apply the transfer function along the second dimension of x and return the 1-D digital filter of each row. Plot the first row of original data against the filtered data.

y = filter(b,a,x,[],2);t = 0:length(x)-1;  %index vectorplot(t,x(1,: ))hold onplot(t,y(1,: ))legend('Input Data','Filtered Data')title('First Row')

Plot the second row of input data against the filtered data.

figureplot(t,x(2,: ))hold onplot(t,y(2,: ))legend('Input Data','Filtered Data')title('Second Row')


[y,zf] = filter(___) also returns the final conditions zf of the filter delays, using any of the previous syntaxes.

这个形式的例子同:

y = filter(b,a,x,zi)


Output Argumentsy — Filtered data% Z; t, G+ y& L8 p+ i
vector | matrix | multidimensional array

Filtered data, returned as a vector, matrix, or multidimensional array of the same size as the input data, x.

If x is of type single, then filter natively computes in single precision, and y is also of type single. Otherwise, y is returned as type double.

Data Types: double | single

zf — Final conditions for filter delays
- f( V& v! p& }/ q: E5 Fvector | matrix | multidimensional array

Final conditions for filter delays, returned as a vector, matrix, or multidimensional array.

  • If x is a vector, then zf is a column vector of length max(length(a),length(b))-1.

  • If x is a matrix or multidimensional array, then zf is an array of column vectors of length max(length(a),length(b))-1, such that the number of columns in zf is equivalent to the number of columns in x. For example, consider using filter along the second dimension (dim = 2) of a 3-by-4-by-5 array x. The array zf has size [max(length(a),length(b))-1]-by-3-by-5.


    7 b4 M: e5 a$ P2 O6 Z! A1 C" k

Data Types: double | single


9 W3 {2 Z- ?  D1 C  I
  • TA的每日心情

    2019-11-29 15:37
  • 签到天数: 1 天

    [LV.1]初来乍到

    2#
    发表于 2020-8-3 14:30 | 只看该作者
    MATLAB之filter 函数介绍(一维数字滤波器)
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    关闭

    推荐内容上一条 /1 下一条

    EDA365公众号

    关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

    GMT+8, 2025-6-24 00:10 , Processed in 0.078125 second(s), 26 queries , Gzip On.

    深圳市墨知创新科技有限公司

    地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

    快速回复 返回顶部 返回列表