Filter Design Toolbox    
filter

Apply a quantized filter to data and access states and filtering information

Syntax

Quantized Filter Syntaxes

Adaptive Filter Syntax

Multirate Filter Syntax

[y,e] = filter(hm,x,d)

Description

This reference page contains three sections that describe the syntaxes for the filter objects:

Quantized Filter Syntaxes

y = filter(hq,x) filters a vector of real or complex input data x through a quantized filter hq, producing filtered output data y. The vectors x and y have the same length.

If x is a matrix, y = filter(hq,x) filters each column of x to produce a matrix y. If x is a multidimensional array, y = filter(hq,x) filters x along the first nonsingleton dimension of x.

[y,zf] = filter(hq,x) produces an additional output argument zf. zf contains the final values for the state vector calculated from zero initial conditions for the state. The form zf takes depends on the data to be filtered and the number of stages in the filter, as detailed in Table 13-3, Final State Form Depends on Filtered Data and Filter Structure.

[...] = filter(hq,x,zi) specifies the initial conditions for the state vector in zi. The form for specifying zi is described in Table 13-2, Initial State Format Depends on the Filter Structure. To specify the same initial condition for all state components, enter zi as a scalar. You can set zi to zero, [], or {} to specify zero (the default) initial conditions.

The form of the initial and final states associated with a quantized filter hq depends on the filter structure and the data to be filtered. The following tables give the form for either entering the initial states or retrieving the final states of the quantized filter.

Table 13-2: Initial State Format Depends on the Filter Structure
Number of Filter Sections
Format of the Initial State
1
A column vector of length s1
n
A 1-by-n cell array of vectors of length si,
i
=1, 2,...,n
Table 13-3: Final State Form Depends on Filtered Data and Filter Structure 
Filtered Data
Number of Filter Sections
Form of the Final State
Vector
1
A column vector of length s1
Vector
n
A 1-by-n cell array of vectors of length si, i=1, 2,...,n
Multidimensional array
1
An s1-by-c matrix
Multidimensional array
n
1-by-n cell array of si-by-c matrices, i=1, 2,...,n

The variables in these tables are described as follows:

To figure out the dimensions of the initial or final conditions, run the filter once with empty initial conditions. Then the final conditions are the right size for the initial conditions:

Look at the size and data type of zf. The initial conditions, zi, will be the same size as zf.

Use the StatesPerSection property of the quantized filter hq to access the number of states in each section. See Quantized Filter Properties Reference for more information on filter properties.

[...] = filter(hq,x,zi,dim) applies the quantized filter hq to the input data located along the specific dimension of x specified by dim.

[y,zf,s,z,v] = filter(hq,x...) returns s, a MATLAB structure containing quantization information (refer to qreport for details); z, the filter's state sequence; and v, the number of overflows at each time step of the filter. When you include four or five output arguments, the input argument x must be a vector. z is a cell array containing the sequence of states at each time step, having 1 element per filter and 1 column per time step. The initial conditions of the kth filter section are in the first column of z{k}:zi{k}=z{k}(:,1). The final conditions of the kth filter section are in the last column of z{k}:zf{k} = z{k}(:,end). Overflows for the kth section are in v{k}.

Adaptive Filter Syntaxes

[y,e] = filter(ha,x,d) filters a vector of real or complex input data x through an adaptive filter object ha, producing the estimated desired response data y and the prediction error e, both resulting from the process of adapting the filter. The vectors x and y have the same length. Use d for the desired signal. Note that d and x must be the same length signal chains.

Multirate Filter Syntaxes

[y,e] = filter(hm,x,d) filters a vector of real or complex input data x through a multirate filter object hm, returning y, the results of the filtering operation and e, the error.

The number of data samples in your input data set x does not need to be a multiple of the rate change factor r for the object. When the rate change factor is not an even divisor of the number of input samples x, filter processes the samples as shown in the following figure, where the rate change factor is 3 and the number of input samples is 23. Decimators always take the first input sample to generate the first output sample. After that, the next output sample comes after each r number of input samples.

Examples

Find the response of a quantized digital filter.

Notice the warnings returned during filter quantization and application. The first warning indicates that one of the filter coefficients overflowed during quantization before converting the filter to second-order section form. Applying the function sos to the filter removed the coefficient overflows. The second warning displays the overflow report, listing details about the filtering operation.

Algorithm

Quantized Filters

The filter command implements fixed- or floating-point arithmetic on the quantized filter structure you specify. The state vector z associated with the filter is a vector whose components are derived from the values of each of the input signals to each delay in the filter. The length of z is the same as the number of delays in the filter.

The implementation of filter depends on the filter structure. For example, the operation of filter at sample m for a direct form II transposed filter is given by the quantized time domain difference equations for y and the states zi shown below. Square brackets denote the quantization that takes place for the input data x, the output data y, the coefficients, the products, and the sums.

Notice that for this df2t filter structure, you divide by a(1). For efficient computation, choose a(1) to be a power of 2.

Adaptive Filters

The algorithm used by filter when you apply an adaptive filter object to a signal depends on the algorithm you chose for your adaptive filter. To learn more about each adaptive filter algorithm, refer to the literature reference provided on the appropriate adaptfilt.algorithm reference page.

Multirate Filters

The algorithm applied by filter when you apply a multirate filter object to a signal depends on the algorithm you chose for the filter--the form of the multirate filter, such as decimator or interpolator. To learn more about each filter algorithm, refer to the literature reference provided on the appropriate multirate filter reference page.

See Also
impz, qfilt, qreport

References
[1] Oppenheim, A.V., and R.W. Schafer, Discrete-Time Signal Processing, Prentice-Hall, 1989.


  fft firceqrip 

Learn more about the latest releases of MathWorks products:

 © 1994-2009 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS