Filter Design Toolbox    
filter

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

Syntax

Description

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 12-13, 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 12-12, 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 12-12: 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 12-13: 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}.

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

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.

See Also
impz        Compute impulse response for quantized filters.

qfilt       Construct a quantized filter.

qreport     Display the contents of the filtering log.

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


 fft firhalfband