| Filter Design Toolbox | ![]() |
Apply a quantized filter to data and access states and filtering information
Syntax
y=filter(Hq,x) [y,zf]=filter(Hq,x) [...]=filter(Hq,x,zi) [...]=filter(Hq,x,zi,dim) [y,zf,s,z,v] = filter(Hq,x...)
Description
y filters a vector of real or complex input data = filter(Hq,x)
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] produces an additional output argument = filter(Hq,x)
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.
[...] specifies the initial conditions for the state vector in = filter(Hq,x,zi)
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.
prod(size(x))/size(x,dim), where dim is the first nonsingleton dimension into which you are filtering.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:
[y,zf] = filter(Hq,x);
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.
[...] applies the quantized filter = filter(Hq,x,zi,dim)
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.
randn('state',0);
x = randn(100,1);
warning on;
[b,a] = butter(3,.9,'high');
Hq = sos(qfilt('referencecoefficients',{b,a}))
Warning: 3 overflows in coefficients.
y = filter(Hq,x);
Warning: 27 overflows in QFILT/FILTER.
Max Min NOverflows NUnderflows NOperations
Coefficient 1 -0.7419 0 0 4
0.8238 -1 0 0 6
Input 2.183 -2.171 27 0 100
Output 0.4361 -0.45 0 0 100
Multiplicand 1 -1 0 2 600
0.4361 -0.45 0 0 700
Product 0.01276 -0.01227 0 0 600
0.4361 -0.45 0 0 700
Sum 0.01278 -0.01221 0 0 300
0.2181 -0.225 0 0 500
Hq.filterstructure
ans =
df2t
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.
Note
Use qreport to display the information logged during a 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.
Note
qfilt/filter does not normalize the filter coefficients automatically. Function filter supplied by MATLAB does normalize the coefficients.
|
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 | ![]() |