[Feature Request] [Smooth] Add median filter to node-red-node-smooth

It would be nice if the "smooth" node (Sign in to GitHub · GitHub) was supporting a window based median filter.
The approach would be, that for each window, something like the following statements would be excecuted

function median(inputArray) {
const sortedInputArray = inputArray.slice().sort((a, b) => a - b);
const middleIndex = Math.floor(sortedInputArray.length / 2);

if (sortedInputArray.length % 2 === 0) {
    return (sortedInputArray[middleIndex - 1] + sortedInputArray[middleIndex]) / 2;
}

return sortedInputArray[middleIndex];

}

I imagine a PR for that would be accepted, as a reasonable addition to the node.

… as long as that sort doesn’t mess with the current set of values ( so they can be shifted out correctly)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.