| Video and Image Processing Blockset™ | ![]() |
Filtering

The 2-D FIR Filter block filters the input matrix I using the coefficient matrix H or the coefficient vectors HH and HV.
| Port | Input/Output | Supported Data Types | Complex Values Supported |
|---|---|---|---|
I | Vector or matrix of intensity values |
| Yes |
H | Matrix of filter coefficients | Same as I port | Yes |
HH | Vector of filter coefficients | Same as I port. The input to ports HH and HV must be the same data type. | Yes |
HV | Vector of filter coefficients | Same as I port. The input to ports HH and HV must be the same data type. | Yes |
PVal | Scalar value that represents the constant pad value | Input must have the same data type as the input to I port | Yes |
Output | Scalar, vector, or matrix of filtered values | Same as I port | Yes |
If the data type of the input is floating point, the output of the block is the same data type. Otherwise, the output can be any fixed-point data type.
Select the Separable filter coefficients check box if your filter coefficients are separable. Using separable filter coefficients reduces the amount of calculations the block must perform to compute the output. For example, suppose your input image is M-by-N and your filter coefficient matrix is x-by-y. For a nonseparable filter with the Output size parameter set to Same as input port I, it would take
![]()
multiply-accumulate (MAC) operations for the block to calculate the output. For a separable filter, it would only take
![]()
MAC operations. If you aren't sure whether or not your filter coefficients are separable, use the isfilterseparable function.
Here is an example of the function syntax, [S, HCOL, HROW] = isfilterseparable(H). The isfilterseparable function takes the filter kernel, H, and returns S, HCOL and HROW. Here, S is a Boolean variable that is 1 if the filter is separable and 0 if it is not. HCOL is a vector of vertical filter coefficients, and HROW is a vector of horizontal filter coefficients. Later, you learn how to use these variables in the block mask.
Use the Coefficient source parameter to specify how to define your filter coefficients. If you select the Separable filter coefficients check box and, for the Coefficient source parameter, you select Specify via dialog, the Vertical coefficients (across height) and Horizontal coefficients (across width) parameters appear in the dialog box. You can use these parameters to enter vectors of vertical and horizontal filter coefficients, respectively. You can use the variables HCOL and HROW, the output of the isfilterseparable function, for these parameters. If you select the Separable filter coefficients check box and, for the Coefficient source parameter, you select Input port, ports HV and HH appear on the block. Use these ports to specify vectors of vertical and horizontal filter coefficients. If you clear the Separable filter coefficients check box and, for the Coefficient source parameter, you select Specify via dialog, the Coefficients parameter appears in the dialog box. Use this parameter to enter your matrix of filter coefficients. If you clear the Separable filter coefficients check box and, for the Coefficient source parameter, you select Input port, port H appears on the block. Use this port to specify your filter coefficient matrix.
The block outputs the result of the filtering operation at the Output port. The dimensions of the output are dictated by the Output size parameter and the sizes of the inputs at ports I and H. For example, assume that the input at port I has dimensions (Mi, Ni) and the input at port H has dimensions (Mh, Nh). If, for the Output size parameter, you choose Full, the output has dimensions (Mi+Mh-1, Ni+Nh-1). If, for the Output size parameter, you choose Same as input port I, the output has the same dimensions as the input at port I. If, for the Output size parameter, you choose Valid, the block filters the input image only where the coefficient matrix fits entirely within it, so no padding is required. The output has dimensions (Mi-Mh+1, Ni-Nh+1). However, if all(size(I)<size(H)), the block errors out.
Use the Padding options parameter to specify how to pad the boundary of your input matrix. To pad your matrix with a constant value, select Constant. To pad your input matrix by repeating its border values, select Replicate. To pad your input matrix with its mirror image, select Symmetric. To pad your input matrix using a circular repetition of its elements, select Circular. For more information on padding, see the Image Pad block reference page.
If, for the Padding options parameter, you select Constant, the Pad value source parameter appears in the dialog box. If you select Specify via dialog, the Pad value parameter appears in the dialog box. Use this parameter to enter the constant value with which to pad your matrix. If, for the Pad value source parameter, you select Input port, the PVal port appears on the block. Use this port to specify the constant value with which to pad your matrix.
Use the Filtering based on parameter to specify the algorithm by which the block filters the input matrix. If you select Convolution and set the Output size parameter to Full, the block filters your input using the following algorithm
![]()
where
and
. If you select Correlation and set the Output size parameter to Full, the block filters your input using the following
algorithm
![]()
where
and
.
The following diagram shows the data types used in the 2-D FIR Filter block for fixed-point signals.

You can set the coefficient, product output, accumulator, and output data types in the block mask as discussed in Dialog Box.
The output of the multiplier is in the product output data type if at least one of the inputs to the multiplier is real. If both of the inputs to the multiplier are complex, the result of the multiplication is in the accumulator data type. For details on the complex multiplication performed, refer to Multiplication Data Types in the Signal Processing Blockset documentation.
The Main pane of the 2-D FIR Filter dialog box appears as shown in the following figure.

Select this check box if your filter coefficients are separable. Using separable filter coefficients reduces the amount of calculations the block must perform to compute the output.
Specify how to define your filter coefficients. Select Specify via dialog to enter your coefficients in the block parameters dialog box. Select Input port to specify your filter coefficient matrix using port H or ports HH and HV.
Enter your real or complex-valued filter coefficient matrix. This parameter is visible if you clear the Separable filter coefficients check box and, for the Coefficient source parameter, you select Specify via dialog. Tunable.
Enter the vector of vertical filter coefficients for your separable filter. This parameter is visible if you select the Separable filter coefficients check box and, for the Coefficient source parameter, you select Specify via dialog.
Enter the vector of horizontal filter coefficients for your separable filter. This parameter is visible if you select the Separable filter coefficients check box and, for the Coefficient source parameter, you select Specify via dialog.
This parameter controls the size of the filtered output. If you choose Full, the output has dimensions (Ma+Mh-1, Na+Nh-1). If you choose Same as input port I, the output has the same dimensions as the input at port I If you choose Valid, output has dimensions (Ma-Mh+1, Na-Nh+1).
Specify how to pad the boundary of your input matrix. Select Constant to pad your matrix with a constant value. Select Replicate to pad your input matrix by repeating its border values. Select Symmetricto pad your input matrix with its mirror image. Select Circular to pad your input matrix using a circular repetition of its elements. This parameter is visible if, for the Output size parameter, you select Full or Same as input port I.
Use this parameter to specify how to define your constant boundary value. Select Specify via dialog to enter your value in the block parameters dialog box. Select Input port to specify your constant value using the PVal port. This parameter is visible if, for the Padding options parameter, you select Constant.
Enter the constant value with which to pad your matrix. This parameter is visible if, for the Pad value source parameter, you select Specify via dialog. Tunable.
Specify the algorithm by which the block filters the input matrix. You can select Convolution or Correlation.
The Fixed-point pane of the 2-D FIR Filter dialog box appears as shown in the following figure.

Select the rounding mode for fixed-point operations.
Select the overflow mode for fixed-point operations.
Choose how to specify the word length and the fraction length of the filter coefficients.
When you select Same word length as input, the word length of the filter coefficients match that of the input to the block. In this mode, the fraction length of the coefficients is automatically set to the binary-point only scaling that provides you with the best precision possible given the value and word length of the coefficients.
When you select Specify word length, you can enter the word length of the coefficients, in bits. In this mode, the fraction length of the coefficients is automatically set to the binary-point only scaling that provides you with the best precision possible given the value and word length of the coefficients.
When you select Binary point scaling, you can enter the word length and the fraction length of the coefficients, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the coefficients. The bias of all signals in the Video and Image Processing Blockset™ is 0.
The filter coefficients do not obey the Rounding mode and the Overflow mode parameters; they are always saturated and rounded to Nearest.
Use this parameter to specify how to designate the product output word and fraction lengths. Refer to Fixed-Point Data Types and Multiplication Data Types in the Signal Processing Blockset™ documentation for illustrations depicting the use of the product output data type in this block:
When you select Same as input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the product output. The bias of all signals in the Video and Image Processing Blockset is 0.
If Coefficent source is set to Input port (on the Main tab), the Product Output will inherit its sign according to the inputs. If either or both input I1 and I2 are signed, the Product Output will be signed. Otherwise, the Product Output is unsigned. The following table shows all cases.
| Sign of Input I1 | Sign of Input I2 | Sign of Product Output |
|---|---|---|
| unsigned | unsigned | unsigned |
| unsigned | signed | signed |
| signed | unsigned | signed |
| signed | signed | signed |
Use this parameter to specify how to designate the accumulator word and fraction lengths. Refer to Fixed-Point Data Types and Multiplication Data Types in the Signal Processing Blockset documentation for illustrations depicting the use of the accumulator data type in this block. The accumulator data type is only used when both inputs to the multiplier are complex:
When you select Same as product output, these characteristics match those of the product output.
When you select Same as input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the accumulator, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the accumulator. The bias of all signals in the Video and Image Processing Blockset is 0.
Choose how to specify the word length and fraction length of the output of the block:
When you select Same as input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the output, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the output. The bias of all signals in the Video and Image Processing Blockset is 0.
Select this parameter to prevent any fixed-point scaling you specify in this block mask from being overridden by the autoscaling tool in the Fixed-Point Tool. For more information, see fxptdlg, a reference page on the Fixed-Point Tool in the Simulink® documentation.
![]() | 2-D FFT | 2-D Histogram (Obsolete) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |