# A Simple Algorithm to Filter / Smooth / Denoise a Noisy Staircase Graph

Is there a way to remove the noise and smooth the graph into a staircase graph.

Assuming you meant to produce something similar to the green line:

$$\text{output}[n] = \max\{\text{input}[n-k], \text{input}[n-k+1], \ldots ,\text{input}[n]\}$$

i.e. you just find the maximum along a sliding window over the last $$k$$ input values?

• It won't yield the green in the middle with the high amplitude. It will also elongate the signal when going form high value to lower one. But it is nice and simple.
– Royi
Jul 25, 2020 at 13:48
• @Royi, Indeed nice and simple
– User
Jul 25, 2020 at 14:00
• One of the unwritten rules of engineering is the simple solution is the right solution. Hence my +1. In case the noise would be whiter and you want to estimate the DC level, then you may use Total Variation based denoising.
– Royi
Jul 25, 2020 at 14:06
• @Royi The simplest solution is usually the right solution
– Ben
Jul 25, 2020 at 15:33
• I'd prefer to do the average of the max samples over the previous n samples, given the otherwise high sensitivity to noise based on any one sample--- but if there is no chance of such "noise" deviation, this answer is perfect, given k should be limited to just the maximum drop time (a sample and hold over 5 samples for example.) The plot seems inconsistent to me, given the region where the selection is along the bottom--- author error? Jul 26, 2020 at 3:15