### Author Topic: Super Simple LPF DSPs.  (Read 6863 times)

0 Members and 1 Guest are viewing this topic.

#### Cognaut

• Full Member
• Posts: 58
• How do you know that I'm not a robot?
##### Super Simple LPF DSPs.
« on: December 02, 2006, 01:47:44 PM »
Let's say that you have some real time signal data streaming in and you want to make it less "bright."

There are two common methods that are used.  One is the decimation and interpolation method.
To decimate and interpolate by two, simply throw out every other sample, effectively reducing your sample rate by half.  Then average the two samples on either side of each new vacancy and use the result as the replacement value for that missing sample.

The other way to dim down your data stream is to use an optimized Finite Impulse Response (FIR) filter.

Private LPF(3) As Long   //  Use a tiny array to hold your data history.  Normally, with an FIR, you
Private x As Long           //  would also have a coefficient table.  This FIR will assume that all
Private y As Long           //  coefficients are 1, allowing us to omit those multipication operations.
Private i As Long

y = input

Private Sub LPF_DSP()
LPF(i) = y
For x = 1 To 3
y = y + LPF((i + 4 - x) AND 3)
Next x
y = y / 4                     // Replacing this division by 4 with two arithmatic shifts
i = (i + 1) AND 3          // will speed up the execution of your code considerably.
End Sub                        // You can also skip this "normalization" step and treat
// the data as if it had gained two bits of resolution.

The output is contained in the variable y, just as the input was.  You'll need to call this routine once for every new sample taken.

Let me know if you find this kind of post helpful.

« Last Edit: December 03, 2006, 10:45:41 AM by Cognaut »

#### JesseWelling

• Expert Roboticist
• Supreme Robot
• Posts: 707
• Only You Can Build A Robot!
##### Re: Super Simple LPF DSPs.
« Reply #1 on: December 02, 2006, 01:57:26 PM »
maybe a definition of lpf and dsp and what they are used for in the real world...
are they used for audio sampling, rf sampling....

#### Cognaut

• Full Member
• Posts: 58
• How do you know that I'm not a robot?
##### Re: Super Simple LPF DSPs.
« Reply #2 on: December 02, 2006, 02:24:29 PM »
Good point.

An LPF is a Low Pass Filter.  It is used to dampen down a digital signal, removing some or all of it's high frequency content.

A DSP is a Digital Signal Process.  It describes a wide variety of algorhythms used to process digital signals.

In the real world, analog signals are converted to digital signals before they can be stored and analyzed by a computer.  You can find LPFs and other DSPs in everything from car stereos to SONAR.  Any signal, be it a recorded sound, radio telescope data or a RADAR image can be processed by a DSP.

An example of a robot oriented LPF application is sensor data stabilization.  It smooths out the sharp bumps.
« Last Edit: December 02, 2006, 02:36:54 PM by Cognaut »

#### JonHylands

• Expert Roboticist
• Supreme Robot
• Posts: 562
• Robot Builder/ Software Developer
##### Re: Super Simple LPF DSPs.
« Reply #3 on: December 02, 2006, 02:53:09 PM »
I have done something similar with my depth sounder sensor readings from my AUV MicroSeeker. The algorithm is a lot simpler - it just takes the current reading from the sensor, averages with the last 5 sensor readings, and that becomes the "replacement" data value. Note that the averaging is always done with the actual history, not the averaged data.

You can see the result of this fairly clearly here:

This first graph is the actual depth sensor readings - it has 4" of resolution with a 10 bit A/D converter.

http://www.huv.com/AUV-Actual.jpg

This is the smoothed data:

http://www.huv.com/AUV-Smooth.jpg

It makes quite a difference...

- Jon

#### Cognaut

• Full Member
• Posts: 58
• How do you know that I'm not a robot?
##### Re: Super Simple LPF DSPs.
« Reply #4 on: December 02, 2006, 03:29:47 PM »
I liked your idea of including a picture - so I copied.
« Last Edit: December 02, 2006, 03:32:33 PM by Cognaut »

• Supreme Robot
• Posts: 11,702
##### Re: Super Simple LPF DSPs.
« Reply #5 on: December 04, 2006, 08:12:47 PM »
Quote
takes the current reading from the sensor, averages with the last 5 sensor readings, and that becomes the "replacement" data value

I usually only use this method to get rid of noise . . . the problem with averaging this way is that your data is always outdated. Of course though, it also depends on things like robot speed, sensor rate, precision required, etc . . .

A modification to this is do a weighting, where older readings have a lower weighting than newer readings.
« Last Edit: December 04, 2006, 08:44:11 PM by Admin »

#### JonHylands

• Expert Roboticist
• Supreme Robot
• Posts: 562
• Robot Builder/ Software Developer
##### Re: Super Simple LPF DSPs.
« Reply #6 on: December 04, 2006, 08:31:45 PM »
It was basically a simple way to get rid of noise. 5 readings happen in half a second, so the data isn't all that old...

- Jon

#### Cognaut

• Full Member
• Posts: 58
• How do you know that I'm not a robot?
##### Re: Super Simple LPF DSPs.
« Reply #7 on: December 04, 2006, 08:57:33 PM »
The weighting is the function of the coefficients that I mentioned.  In this example, I'm using all ones.  That's because I'm only looking to dampen down the signal.  It works well without the heavy math ops.

The delay for this FIR is two samples, if you take the delay to mean the center point of the phase shifts created by the four taps.

If you take the suggestion to eliminate the /4 and treat the data as if it gained two bits of resolution, then the whole filter is performed using only additions and subtractions, which makes it very fast.

The reason that I use the average of 4 values is because I find the use of 2^n and ((2^n)-1) a great way to stream line the code.  Notice the use of "AND 3" as the pointer MODULUS.
« Last Edit: December 04, 2006, 11:54:29 PM by Cognaut »

#### JesseWelling

• Expert Roboticist
• Supreme Robot
• Posts: 707
• Only You Can Build A Robot!
##### Re: Super Simple LPF DSPs.
« Reply #8 on: December 04, 2006, 09:38:05 PM »
speaking of which I have some bouncy IR sensors... those pesky sharp kind...
should I use a capacitor? I'm trying to get readings every 50ms which is to fast to
do averaging because the sharps only update every 30ms....
any ideas?

#### JonHylands

• Expert Roboticist
• Supreme Robot
• Posts: 562
• Robot Builder/ Software Developer
##### Re: Super Simple LPF DSPs.
« Reply #9 on: December 04, 2006, 09:50:24 PM »
Yeah, you definitely want a capacitor in there. Most people recommend putting a 0.01 uF ceramic cap very close to the sensor, between ground and power.

I typically put a big-ass electrolyte capacitor in my robots, on the 5 volt side of things. I usually use this one:

http://www.solarbotics.com/products/index.php?scdfa-250100084-viewDetail-productzq377zq4categoryzq34=true

Coupled with a number of 0.01 uF ceramic caps in various places.

- Jon