# November 16, 2017

## Impulse Noise Filtering - Slew Limit Filter

In the past few articles in this series I have demonstrated using a median filter to mitigate impulse noise. The problem with a median filter is that even using a small window size and taking advantage of the speed of a mostly sorted list entering an insertion sort, the filter is still significantly slower than a windowed average. There is another option. It does not filter as nicely as a median filter but does help to dampen impulse noise.

The slew rate is a measure of how quickly voltage changes over time. A windowed average acts as limiter on slew rate but usually not enough to attenuate impulse noise. However one can directly limit the slew rate of a signal. The equation is quite simple:

For each sample of the input (*a*_{n}) the filter output (*f*_{n}) has its change (Δ_{n}) limited to the last to some maximum (*s*_{max}). If the magnitude of change is less than the maximum, the filter output is the same as the input. If the magnitude exceeds the change the filtered output is modified by the maximum change but no further.

Following the examples of previous article on this subject, here is an example of the filter output:

There is some distortion on the signal caused by the impulse noise but the filtered output is fairly effective at eliminating the large spikes. When used in combination with a first-order low-pass filter the input signal is fairly clear.

The reason this kind of filter is attractive is because of how simple it is to implement.

// Uses:

// In-place filter of input buffer.

// Input:

// data - Data to filtered..

// dataSize - Number of data points.

// limit - Maximum change allowed.

// Output:

// Filtered output is returned in 'data'.

// Author:

// Andrew Que <https://www.DrQue.net/>

//-----------------------------------------------------------------------------

static inline void slewLimitFilter

(

int * data,

size_t dataSize,

int limit

)

{

for ( size_t index = 1; index < dataSize; index += 1 )

{

int delta = data[ index ] - data[ index - 1 ];

if ( delta > limit )

data[ index ] = data[ index - 1 ] + limit;

else

if ( delta < -limit )

data[ index ] = data[ index - 1 ] - limit;

}

}

Just as with any filter, artifacts are introduced by the slew limit filter.

This sine wave has become a triangle wave because the slew limit is too low. This shape is the result of the filter attenuating the actual data signal. This is an other demonstration.

Here is a clean signal, but because the slew limit is too low the filter cannot keep up with the rate of change of the true signal.

The other problem with the slew limit filter is that it is not very strong.

Here the impulse noise has been doubled and the filter has produced a very messy result. So the filter is clearly not a replacement for a median filter. If you can afford the processing power, use the median filter. If you cannot, the slew limit filter may be a possibility. It depends on what the impulse noise looks like, and how much signal distortion can be tolerated.