# Remove noise on nonlinear signal

This signal represents a drawn line. For some reason, the device showed interference as shown in the figure below: The question is: how can I remove the interference, making the signal as continuous as possible?

Any suggestions?

• A median filter should remove most glitches, but not the final burst in your signal. – Juancho Feb 22 '17 at 7:05

Most of the noise you've circled looks like impulsive noise meaning a small number of sudden impulses or spikes. You can remove this reliably with an impulse rejection filter. The response of this filter is usually defined as $$y_k = \left\{ \begin{array}{cc} x_k, & |x_k - m_k| \le t S_k \\ m_k, & |x_k - m_k| > t S_k \end{array} \right.$$ Here, $m_k$ is the median of a window centered on sample $x_k$, and $S_k$ is a robust scale estimate of the same window, such as the median absolute deviation (MAD). The choice of the MAD as the scale estimate is also known as the Hampel filter in the statistics literature, though you can choose other scale estimates, such as IQR, $S_n$, $Q_n$ etc.
$t$ is a tuning parameter indicating how many scale estimates away from the median are allowed before flagging the point as an outlier, or impulse. If the current sample is less than $t$ scales away from the local median, the filter does nothing. Otherwise it replaced the sample with the local median.