← All problems

Median Filter

Hard · Sequential · SystemVerilog · VHDL

Design a sliding-window median filter.

A median filter replaces each sample of a stream with the median of the last few samples. Unlike an average, a median ignores a single outlier entirely, so the filter removes impulse noise (one wild sample) while keeping steps in the signal sharp, which makes it a common first stage for sensor and image data.

The window is the last WIN samples accepted, with WIN odd. A cycle with valid_in high accepts data_in, an unsigned number, as a sample. In the cycle after a sample, valid_out is high if at least WIN samples have been accepted since reset, and median_out is then the median of the window: its middle value when sorted. In every other cycle valid_out is low and median_out may hold any value.

resetn is a synchronous, active-low reset that empties the window and clears valid_out; it overrides valid_in.

  • Sorting & search

Open this challenge in the editor →