Share Line Buffer Across Filters with Different Neighborhood Sizes
R2026bThis example shows how to use a single line buffer for multiple filters that require different neighborhood sizes.
Reusing one line buffer, configured to return the largest neighborhood, reduces resource usage on the target FPGA and also supports filters with smaller neighborhoods. This example provides a Neighborhood Slicer subsystem which extracts sub-neighborhoods from the shared line buffer output. The Neighborhood Slicer subsystem selects a subset of rows and gates the shift enable signal.
The example model contains a single shared Line Buffer block that drives four Image Filter blocks. The filters are configured for 7-by-7, 5-by-7, 7-by-5, and 3-by-5 neighborhoods, respectively. The Line Buffer selects the largest required neighborhood size (7-by-7) and outputs a single column of 7 pixels each clock cycle, along with pixel control signals and a shift enable signal. Each Image Filter block accepts neighborhood input from this external line buffer rather than using its own internal line buffer.
Workspace variables define the video format and the line buffer parameters used by the blocks in the model. The video format is defined by these dimensions:
Active Pixels per Line (APPL)
Active Video Lines (AVL)
Total Pixels per Line (TPPL)
Total Video Lines (TVL)
Starting Active Line (SAL)
Front Porch (FP)
For more details on these parameters, see the Frame To Pixels block. The TPPL value in this example supports a maximum neighborhood width of 7 when operating on 8 pixels per clock.
% Video format timings APPL = 64; AVL = 18; TPPL = APPL + 7 * 8; TVL = AVL + 10; SAL = 2; FP = 32; % Line Buffer parameters paddingValue = 16; lineBufferSize = 2^nextpow2(APPL+1); % Simulation stop time stopTime = TVL * TPPL * 2; open_system('LineBufferSharingAcrossFiltersModel');
Configure Shared Line Buffer
The Line Buffer block stores incoming pixel data and outputs columns of the neighborhood one column at a time. To support the largest filter, set the Neighborhood size parameter to cover the maximum number of rows and columns required. In this model, the largest filter requires a 7-by-7 neighborhood. The Line Buffer block sets Neighborhood size to [7, 7].
The Line Buffer outputs a 7-element column vector representing one vertical slice of the neighborhood on each clock cycle. It also outputs a pixelcontrol bus and a shiftEnable signal. The shiftEnable signal indicates when the Image Filter should shift new column data into its internal neighborhood register.
Configure Filters to Use External Line Buffer
Each Image Filter block has a Line buffer source parameter that controls whether the block uses its own internal line buffer or accepts data from an external source. To share the Line Buffer's output across multiple filters, set this parameter to "External" on each Image Filter block.
When you set the Line buffer source parameter to External, the Image Filter block expects three inputs in addition to the coefficient data:
A column of pixel data (from the Line Buffer output)
A
pixelcontrolbusA shift enable signal
The Image Filter block constructs the two-dimensional neighborhood by shifting in a column of data each time the shiftEnable signal is true. The filter then applies the specified coefficients to the neighborhood to produce the next output pixel.
In this model, the 7-by-7 filter connects directly to the Line Buffer outputs without modification. The remaining filters (5-by-7, 7-by-5, and 3-by-5) require custom logic between the Line Buffer and the Image Filter to adapt the neighborhood size.
Extract Smaller Neighborhoods from Shared Line Buffer
When a filter requires a neighborhood smaller than the 7-by-7 output of the shared Line Buffer, custom logic adapts the data in two dimensions:
Neighborhood height (rows): Select the central rows from the 7-element column output.
Neighborhood width (columns): Gate the shift enable signal to reduce the number of padding columns.
These two adaptations are handled by the Neighborhood Slicer subsystem between the shared Line Buffer and each Image Filter that requires a smaller neighborhood. The subsystem supports HDL code generation. In the subsystem mask, specify the input neighborhood size, the output neighborhood size, and the number of pixels per clock. The Input neighborhood size and Number of pixels must match the upstream Line Buffer and pixel stream. For an even Output neighborhood size, configure the Output neighborhood center bias; the input neighborhood must be top-left biased.
This approach prioritizes low latency operation over resilience to errors in the pixelcontrol bus and/or shiftEnable signal. To make this conversion more resilient to errors, you can add a tapped delay line (TDL) of length greater than or equal to half of the neighborhood width with a finite-state-machine (FSM). You can tailor the FSM to use the information captured in the TDL to determine when to allow or halt dataflow to the Neighborhood Slicer and when to reset the HDL Counter, for example, if a new hStart and valid are received.

Adapt Neighborhood Height
The Line Buffer outputs a column vector with 7 elements, representing the full vertical extent of the 7-by-7 neighborhood. For filters with fewer rows, the Neighborhood Slicer selects the central pixels of the column that correspond to the desired neighborhood height.
For example, a 5-by-7 filter needs 5 rows. From the 7-element column, select pixels 2 through 6 (the central 5 values). A 3-by-5 filter needs 3 rows, so select pixels 3 through 5.
In hardware, row index selection maps directly to wiring and does not consume additional FPGA resources.
Adapt Neighborhood Width
The neighborhood width determines how many columns of data the Image Filter shifts into its internal register. The Line Buffer asserts the shiftEnable signal for a number of clock cycles that corresponds to the full neighborhood width (7 columns for a 7-by-7 configuration), including padding columns at the start and end of each video line.
To reduce the neighborhood width for a smaller filter, the Neighborhood Slicer gates the shiftEnable signal so that it is false for the extra padding cycles. This operation narrows the neighborhood by reducing the total number of columns shifted into the Image Filter.
For example, a 7-by-5 filter requires 5 columns instead of 7. The Neighborhood Slicer removes one padding cycle from the start and one from the end of each line, so the Image Filter receives shiftEnable pulses for only 5 columns of valid and padded data.
The pixelcontrol signals pass through unchanged. The subsystem manipulates only the shiftEnable signal to control the effective neighborhood width.
