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

**URL:** <https://discourse.nodered.org/t/feature-request-smooth-add-median-filter-to-node-red-node-smooth/60359>\
**Category:** Feature Requests\
**Created:** [25 March 2022 22:15 UTC](https://discourse.nodered.org/t/feature-request-smooth-add-median-filter-to-node-red-node-smooth/60359 "2022-03-25T22:15:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andowinger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andowinger/32/59083_2.png) [@andowinger](https://discourse.nodered.org/u/andowinger)\
**Post date:** [25 March 2022 22:15 UTC](https://discourse.nodered.org/t/feature-request-smooth-add-median-filter-to-node-red-node-smooth/60359/1 "2022-03-25T22:15:44Z")

</div>

It would be nice if the "smooth" node ([Sign in to GitHub · GitHub](https://github.com/node-red/node-red-nodes/issues/new)) 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];
> 
> ```
> 
> }

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2022 21:36 UTC](https://discourse.nodered.org/t/feature-request-smooth-add-median-filter-to-node-red-node-smooth/60359/2 "2022-03-26T21:36:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 March 2022 21:44 UTC](https://discourse.nodered.org/t/feature-request-smooth-add-median-filter-to-node-red-node-smooth/60359/3 "2022-03-26T21:44:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 May 2022 21:45 UTC](https://discourse.nodered.org/t/feature-request-smooth-add-median-filter-to-node-red-node-smooth/60359/4 "2022-05-25T21:45:05Z")

</div>

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