FAILURE MAP
← Case archive

FA-91456 / Digital signal filters / Open access

Median filter window stops one sample early · case 01

The window is asymmetric and lags the signal by half a sample.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The slice end is i + h instead of i + h + 1.

THE FAILURE

The slice end is i + h instead of i + h + 1.

Unsuccessful approach: The attempted repair slices to i + k, making the window extend too far forward.

Case contract

Input [K, samples]; K odd ("bad-kernel" otherwise). Output i is the median of samples[i-K//2 .. i+K//2] clipped to the valid range (shrinking windows at the edges); an even count uses the mean of the two middle values. Return exact fraction strings.

Why this case matters

Median filters remove impulse noise without blurring edges; window or tie handling slips shift features.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    k, xs = x
    if k < 1 or k % 2 == 0:
        return 'bad-kernel'
    h = k // 2
    out = []
    for i in range(len(xs)):
        win = sorted(xs[max(0, i - h):i + h])
        m = len(win)
        if m % 2:
            out.append(str(Fraction(win[m // 2])))
        else:
            out.append(str(Fraction(win[m // 2 - 1] + win[m // 2], 2)))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: unsorted window', [3, [5, 1, 9, 2]], ['3', '5', '2', '11/2']], ['regression: edge even median', [3, [4, 1, 7]], ['5/2', '4', '4']], ['regression: negative odd sum', [3, [-3, 0, 5]], ['-3/2', '0', '5/2']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['regression: duplicates', [3, [2, 2, 5, 2]], ['2', '2', '2', '7/2']]], [['regression: negative odd sum', [3, [-3, 0, 5]], ['-3/2', '0', '5/2']], ['regression: random median 2', [3, [5, 5, 3, -5, 8, -1]], ['5', '5', '3', '3', '-1', '7/2']], ['regression: random median 4', [3, [0, -4, -4, 3]], ['-2', '-4', '-4', '-1/2']], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['regression: duplicates', [3, [2, 2, 5, 2]], ['2', '2', '2', '7/2']]], [['regression: random median 5', [3, [2, -2, -2, -2, -4, -4]], ['0', '-2', '-2', '-2', '-4', '-4']], ['regression: random median 6', [3, [3, 9, 2, 4, 6, 3, -4]], ['6', '3', '4', '4', '4', '3', '-1/2']], ['regression: random median 4', [3, [0, -4, -4, 3]], ['-2', '-4', '-4', '-1/2']], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['regression: negative odd sum', [3, [-3, 0, 5]], ['-3/2', '0', '5/2']]], [['regression: random median 12', [3, [7, 1, -5, -5, -5, 2, 5, -5]], ['4', '1', '-5', '-5', '-5', '2', '2', '0']], ['regression: random median 13', [3, [1, -4, -1, 3, 9, 4, 6, 2]], ['-3/2', '-1', '-1', '3', '4', '6', '4', '4']], ['regression: random median 6', [3, [3, 9, 2, 4, 6, 3, -4]], ['6', '3', '4', '4', '4', '3', '-1/2']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['regression: random median 2', [3, [5, 5, 3, -5, 8, -1]], ['5', '5', '3', '3', '-1', '7/2']]], [['regression: random median 18', [5, [-4, 9, 8, -3, -2]], ['8', '5/2', '-2', '3', '-2']], ['regression: random median 19', [3, [7, 8, -4]], ['15/2', '7', '2']], ['regression: random median 12', [3, [7, 1, -5, -5, -5, 2, 5, -5]], ['4', '1', '-5', '-5', '-5', '2', '2', '0']], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['regression: random median 4', [3, [0, -4, -4, 3]], ['-2', '-4', '-4', '-1/2']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression: unsorted window['5', '3', '5', '11/2']['3', '5', '2', '11/2']Failed
regression: edge even median['4', '5/2', '4']['5/2', '4', '4']Failed
regression: negative odd sum['-3', '-3/2', '5/2']['-3/2', '0', '5/2']Failed
control: even kernelbad-kernelbad-kernelPassed
control: even kernel fourbad-kernelbad-kernelPassed
control: random median 0['-2', '-2', '-2', '3']['-2', '-2', '-2', '3']Passed
regression: duplicates['2', '2', '7/2', '7/2']['2', '2', '2', '7/2']Failed

SHA-256 / f1746def34cc2b709453e8bd91ab733010a36c8374d37c748f13730ff043dc7e

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    k, xs = x
    if k < 1 or k % 2 == 0:
        return 'bad-kernel'
    h = k // 2
    out = []
    for i in range(len(xs)):
        win = sorted(xs[max(0, i - h):i + k])
        m = len(win)
        if m % 2:
            out.append(str(Fraction(win[m // 2])))
        else:
            out.append(str(Fraction(win[m // 2 - 1] + win[m // 2], 2)))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: unsorted window', [3, [5, 1, 9, 2]], ['3', '5', '2', '11/2']], ['regression: edge even median', [3, [4, 1, 7]], ['5/2', '4', '4']], ['regression: negative odd sum', [3, [-3, 0, 5]], ['-3/2', '0', '5/2']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['regression: duplicates', [3, [2, 2, 5, 2]], ['2', '2', '2', '7/2']]], [['regression: negative odd sum', [3, [-3, 0, 5]], ['-3/2', '0', '5/2']], ['regression: random median 2', [3, [5, 5, 3, -5, 8, -1]], ['5', '5', '3', '3', '-1', '7/2']], ['regression: random median 4', [3, [0, -4, -4, 3]], ['-2', '-4', '-4', '-1/2']], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['regression: duplicates', [3, [2, 2, 5, 2]], ['2', '2', '2', '7/2']]], [['regression: random median 5', [3, [2, -2, -2, -2, -4, -4]], ['0', '-2', '-2', '-2', '-4', '-4']], ['regression: random median 6', [3, [3, 9, 2, 4, 6, 3, -4]], ['6', '3', '4', '4', '4', '3', '-1/2']], ['regression: random median 4', [3, [0, -4, -4, 3]], ['-2', '-4', '-4', '-1/2']], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['regression: negative odd sum', [3, [-3, 0, 5]], ['-3/2', '0', '5/2']]], [['regression: random median 12', [3, [7, 1, -5, -5, -5, 2, 5, -5]], ['4', '1', '-5', '-5', '-5', '2', '2', '0']], ['regression: random median 13', [3, [1, -4, -1, 3, 9, 4, 6, 2]], ['-3/2', '-1', '-1', '3', '4', '6', '4', '4']], ['regression: random median 6', [3, [3, 9, 2, 4, 6, 3, -4]], ['6', '3', '4', '4', '4', '3', '-1/2']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['regression: random median 2', [3, [5, 5, 3, -5, 8, -1]], ['5', '5', '3', '3', '-1', '7/2']]], [['regression: random median 18', [5, [-4, 9, 8, -3, -2]], ['8', '5/2', '-2', '3', '-2']], ['regression: random median 19', [3, [7, 8, -4]], ['15/2', '7', '2']], ['regression: random median 12', [3, [7, 1, -5, -5, -5, 2, 5, -5]], ['4', '1', '-5', '-5', '-5', '2', '2', '0']], ['control: even kernel four', [4, [1, 5, 2, 8]], 'bad-kernel'], ['control: random median 0', [3, [-2, -2, -2, 8]], ['-2', '-2', '-2', '3']], ['control: even kernel', [2, [1, 2, 3]], 'bad-kernel'], ['regression: random median 4', [3, [0, -4, -4, 3]], ['-2', '-4', '-4', '-1/2']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression: unsorted window['5', '7/2', '2', '11/2']['3', '5', '2', '11/2']Failed
regression: edge even median['4', '4', '4']['5/2', '4', '4']Failed
regression: negative odd sum['0', '0', '5/2']['-3/2', '0', '5/2']Failed
control: even kernelbad-kernelbad-kernelPassed
control: even kernel fourbad-kernelbad-kernelPassed
control: random median 0['-2', '-2', '-2', '3']['-2', '-2', '-2', '3']Passed
regression: duplicates['2', '2', '2', '7/2']['2', '2', '2', '7/2']Passed

SHA-256 / 5d2efec7c6cce48b9e8a9b737387a813202f99f888e472df60014ce7c0dd2d29

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 7 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; exact rational arithmetic or fixed-decimal rounding keeps outputs strict JSON. It is not a production DSP library and claims no standards conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:51:36.188249+00:00.

Case digest / 275db9cd711feb108211d6b35d601b1e8cc458d51cc74aa04bccaaeca76a9dae