Documentation

筛选

1-D digital filter

Syntax

y =滤波器(b,a,x)
y =滤波器(b,a,x,zi)
y = filter(b,a,x,zi,dim)
[y,zf] = filter(___)

描述

example

y=过滤器(b,a,x)筛选s the input dataxusing arational transfer functiondefined by the numerator and denominator coefficientsbanda

Ifa(1)不等于1, then筛选通过a(1)。Therefore,a(1)must be nonzero.

  • Ifxis a vector, then筛选返回过滤数据作为与相同大小的向量x

  • Ifx是矩阵,然后筛选沿着第一个维度起作用,并返回每列的过滤数据。

  • Ifx是一个多维数组,然后筛选沿着大小不等于1的第一个数组尺寸作用。

example

y=过滤器(b,a,x,Zi)使用初始条件Zifor the filter delays. The length ofZi必须等于max(length(a),length(b))-1

example

y=过滤器(b,a,x,Zi,dim)沿维度行事dim。例如,如果x是矩阵,然后筛选(b,a,x,zi,2)返回每行的过滤数据。

example

[y,ZF] =过滤器(___)also returns the final conditionsZF过滤器延迟,使用任何先前的语法。

例子

collapse all

移动平均过滤器是一种用于平滑嘈杂数据的常见方法。此示例使用筛选function to compute averages along a vector of data.

创建正弦数据的1 x 100行矢量,该数据被随机噪声损坏。

t = linspace(-pi,pi,100); rng默认%初始化随机数生成器x = sin(t) + 0.25*rand(size(t));

移动平均过滤器滑动一个长度的窗口沿数据,计算每个窗口中包含的数据的平均值。以下差方程定义了向量的移动平均过滤器:

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

Windowsize = 5;b =(1/windowsize)*一个(1,Windowsize);a = 1;

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

y =滤波器(b,a,x);情节(t,x)保持on情节(t,y)传奇('Input Data',“过滤数据”)

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

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

rng默认%初始化随机数生成器x = rand(2,15);

为有理传递函数定义分子和分母系数。

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

Apply the transfer function along the second dimension ofx并返回每行的1-D数字过滤器。针对过滤数据绘制原始数据的第一行。

y =滤波器(b,a,x,[],2);t = 0:长度(x)-1;%index vector情节(t,x(1,:))on情节(t,y(1,:))传奇('Input Data',“过滤数据”) 标题('First Row')

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

图图(t,x(2,:))保持on情节(t,y(2,:))传奇('Input Data',“过滤数据”) 标题('Second Row')

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,x1andx2

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

The whole sequence,x,是垂直串联x1andx2

定义有理传输函数的分子和分母系数,

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

Filter the subsequencesx1andx2one at a time. Output the final conditions from filteringx1在第一部分的末尾存储过滤器的内部状态。

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

Use the final conditions from filteringx1作为过滤第二部分的初始条件,x2

Y2 =滤波器(B,A,X2,ZF);

Y1is the filtered data fromx1, andY2S从x2。The entire filtered sequence is the vertical concatenation ofY1andY2

同时过滤整个序列以进行比较。

y =滤波器(b,a,x);isequal(y,[y1;y2])
ans =logical1

Input Arguments

collapse all

分子系数rational transfer function, specified as a vector.

数据类型:双倍的|单身的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64|logical
Complex Number Support:是的

Denominator coefficients of therational transfer function, specified as a vector.

数据类型:双倍的|单身的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64|logical
Complex Number Support:是的

输入数据, specified as a vector, matrix, or multidimensional array.

数据类型:双倍的|单身的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64|logical
Complex Number Support:是的

过滤器延迟的初始条件,指定为矢量,矩阵或多维数组。

  • IfZi是矢量,其长度必须是max(length(a),length(b))-1

  • IfZi是矩阵或多维阵列,然后the size of the leading dimension must bemax(length(a),length(b))-1。每个剩余维度的大小必须与相应维度的大小相匹配x。例如,考虑使用筛选沿着second dimension (DIM = 2) of a 3-by-4-by-5 arrayx。数组Zimust have size [max(length(a),length(b))-1] -by-3-by-5。

默认值,由[],将所有过滤器延迟初始化为零。

数据类型:双倍的|单身的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64|logical
Complex Number Support:是的

Dimension to operate along, specified as a positive integer scalar. If no value is specified, then the default is the first array dimension whose size does not equal 1.

考虑二维输入阵列,x

  • IfDIM = 1, then筛选(b,a,x,zi,1)沿着行xand returns the filter applied to each column.

  • IfDIM = 2, then筛选(b,a,x,zi,2)沿着列的作品x并返回应用于每一行的过滤器。

Ifdimis greater thanndims(x), then筛选returnsx

数据类型:双倍的|单身的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64|logical

输出参数

collapse all

过滤数据,作为向量,矩阵或多维数组返回,其大小与输入数据相同,x

Ifx是类型单身的, then筛选natively computes in single precision, andyis also of type单身的。Otherwise,y被返回为类型双倍的

数据类型:双倍的|单身的

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

  • Ifxis a vector, thenZFis a column vector of lengthmax(length(a),length(b))-1

  • Ifx是矩阵或多维阵列,然后ZF是长度为长的列数的数组max(length(a),length(b))-1, such that the number of columns inZFis equivalent to the number of columns inx。例如,考虑使用筛选沿着second dimension (DIM = 2) of a 3-by-4-by-5 arrayx。数组ZFhas size [max(length(a),length(b))-1] -by-3-by-5。

数据类型:双倍的|单身的

More About

collapse all

有理转移函数

The input-output description of the筛选operation on a vector in the Z-transform domain is a rational transfer function. A rational transfer function is of the form,

Y ( z ) = b ( 1 ) + b ( 2 ) z - 1 + ... + b ( n b + 1 ) z - n b 1 + a ( 2 ) z - 1 + ... + a ( n a + 1 ) z - n a X ( z ) ,

处理FIR和IIR过滤器[1]na是反馈过滤顺序,以及nbis the feedforward filter order.

You also can express the rational transfer function as the following difference equation,

a ( 1 ) y ( n ) = b ( 1 ) x ( n ) + b ( 2 ) x ( n - 1 ) + ... + b ( n b + 1 ) x ( n - n b ) - a ( 2 ) y ( n - 1 ) - ... - a ( n a + 1 ) y ( n - n a )

此外,如下图所示,您可以使用其直接表格II转置实现来表示有理传输函数。由于归一化,假设A(1)= 1

操作筛选at samplemis given by the time domain difference equations

y ( m ) = b ( 1 ) x ( m ) + z 1 ( m - 1 ) z 1 ( m ) = b ( 2 ) x ( m ) + z 2 ( m - 1 ) - a ( 2 ) y ( m ) = z n - 2 ( m ) = b ( n - 1 ) x ( m ) + z n - 1 ( m - 1 ) - a ( n - 1 ) y ( m ) z n - 1 ( m ) = b ( n ) x ( m ) - a ( n ) y ( m )

提示

  • 如果您具有信号处理工具箱™,则可以设计一个过滤器,d, 使用Designfilt。然后,您可以使用Y = filter(d,X)to filter your data.

参考

[1]Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck.Discrete-Time Signal Processing。新泽西州上萨德尔河:Prentice-Hall,1999年。

扩展功能

Introduced before R2006a

Was this topic helpful?