November 16, 2017

Impulse Noise Filtering - Slew Limit Filter

Math, Programming, Impulse Noise Filtering

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 (an) the filter output (fn) has its change (Δn) limited to the last to some maximum (smax). 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.

November 15, 2017

The ride home today was into a serious headwind.  The winds were WNW at 22 MPH (35 kph) with gusts of 25 MPH.  The temperature was 45°F (7°C) but with winds that high it made for heads-down cycling.

Jake.

November 13, 2017

Didn't bike in today and honestly, it felt weird.

November 12, 2017

Coffee, laptop and fire.  That's a good evening.

November 11, 2017

Preparations for the next weekend.

November 10, 2017

Friday is typically the day for breakfast on State Street.  The temperature had plunged lower than forecast and was 14°F (-10°C) when I left the house.  After breakfast it had dropped to 12°F (-11°C).  I wore my light coat (the one too warm for 30 degree weather) and pair of pants over my fleece pants.  The ride was slow and sweaty but aside from my face (cheeks in particular) I was not cold.
I approached Lake Monona from Broom Street and saw a really interesting phenomenon.  The lake water is still holding more than enough heat to keep from freezing and with the drastically colder air temperatures there was steam forming on the surface.  Steady winds were blowing the steam across the lake and it was really neat to see.  Although not warmed up and knowing it would be cold I had to stop for a couple pictures.  My hands hated me for it, but I do like what I captured.
When my work day ended the temperature had climbed to 25°F (-4°C) and the winds were now mostly from the east.  I decided to try riding home in just fleece and no coat.  People driving by me must have thought I was crazy but I felt fairly comfortable.  Knowing that if I stopped I would get too cold to continue riding at speed I skipped my slice of pizza and rode directly home.  With about 2 miles left to go I really felt my body fatigue.  I had been hungry for a couple miles but now I was really hungry and really tired.  My heart rate dropped to the 130 BPM range which is quite low for riding and I was a little concerned I wouldn't be able to keep my body heat up high enough for the clothing I had on.  I had a coat and even a pair of pants on the bike with me so I wasn't all that worried but I didn't really want to use them.  However the lower heart rate didn't seem to be a problem.  My core temperature was already up and the fleece was keeping that heat in.  So I made it home fine, just hungry and tired.  Luckily, I know how to fix both of those issues and did so right away.
Today marks 190 miles for the month of November, and 3,801 miles for the year.  I think I am on track for hitting 4,000 miles by year's end as I only needed to complete 200 miles this month.  While the riding hasn't been nearly as nice as October I have found I am performing quite well compared to past years.  Riding in clothing just heavy enough to keep warm seems to be the trick to comfortable winter cycling.

November 09, 2017

The ride into work was quite warm when I set out, around at 41°F (5°C), and I had a tailwind of 8 MPH (13 kph).  That would be the highest temperature all day.  When I left work the temperature was 30°F and still falling.  Winds had picked up to 15 MPH (24 kph) with guests of 28 MPH (45 kph) mostly from the north.  I had a meeting on campus and knew the John Nolen bridge to the isthmus was going to be a gauntlet.  Still, I decided to try the ride in just my fleece shirt and pants.  As before, the first few minutes were a little cold but once I warmed up I felt pretty good.  The wind on my face was my biggest complaint.  Riding through Monona on Waunona Way I would get occasional guests off the lake and they were enough to require steering corrections.  Then I reached Olin Park which I knew was the last of my wind break.
The bridge between Monona Bay and Lake Monona is over a half-mile long, and with nothing but the lakes on either side there is no protection from the wind.  The bridge starts out running north north-west, and then turns north north-east.  Winds were NNW and I would be going directly into them.  By this point, however, I had build up sufficient core body temperature and with my legs already warmed up from the previous 20 minutes of riding the bridges turned out not to be nearly as bad as I thought they would.
I made it downtown and went inside for my customary slice of pizza where I changed out of my fleece shirt and put on a coat.  Since I had a meeting on campus I next went to a coffee shop to do a little writing while I waited.  By this time I had started to notice I had become quite cold and was shivering.  This lasted about 10 minutes and wasn't the first time it has happened.  Seems that I can take the cold when moving, but when I get indoors and stop moving I get cold.  Strange that I can handle the temperatures when outside, but inside where it is warm is where I have the problem.
The temperature had fallen to around 27°F (-3°C) during my ride and was down to 25°F (-4°C) by the time I left the coffee shop.  When I finished my meeting on campus the temperature was down to 21°F (-6°C) and the winds still high.  I put on my coat and a pair of pants for the ride home.  With the wind and restricted movement from the heavy clothing I averaged 10 MPH (16 kph) instead of my more typical 14 MPH (23 kph).  It was a difficult day for riding and tomorrow is forecast to be worse.  Yet I am pleased with my cold weather performance.
Pictured is sunrise over Paunack Park.

November 08, 2017

Sunrise on my drive into work.

November 07, 2017

Finding my new jacket too warm for use in the 30°F (-1°C) range and the success with my fleece lined pants I decided to order a new fleece lined shirt.  This morning on my ride to work I tried it out.  The temperature was 34°F (1°C) and I wore just the fleece shirt and pants for my ride into work.  The first couple of minutes were a bit chilly but I warmed up quickly and the remainder of the ride was quite comfortable.  I think fleece maybe my new favorite cool weather fabric.