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

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.

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.

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.

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.

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.

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 todo averaging because the sharps only update every 30ms....any ideas?