[chbot] Filter

mikael stewart mikael.stewart at gmail.com
Wed Oct 17 23:28:42 BST 2018


You could use a simple IIR filter that weights the most recent input by say
1/100th:

filt_value = (filtered_value * 99 + raw_value) / 100;

If filt_value is floating point and the calculation is done in an
approximately constant loop interval this works well.

This can also be done with integers noting the result of "(filtered_value *
99) + raw_value" should not exceed the size of the integer.

The quantization is not so nice in the above method though because it gets
multiplied by the * 99. A better way might be to keep track of a running
sum with one variable, and use a second variable for the filtered result:

filt_sum = filt_sum - filt_sum / 100 + raw_value;
filt_value = filt_sum / 100;

The second line only needs to be evaluated when you actually need to use
the result.

Cheers

Mikael


On Thu, Oct 18, 2018 at 9:06 AM Marshland Engineering <
marshland at marshland.co.nz> wrote:

> I need to do some software filtering. I'm reading a camshaft with a 0.001
> linear scale and there is quite a bit of noise in the data. Looking on the
> web
> has left me non the wiser. Rectangular or Triangle filters are an option
> but
> these will loose some data integrity. The profile is a very gentle curve
> with
> the data around the ctr line.
>
> I hoping for something simple !!!!
>
> Thanks Wallace.
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> https://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20181018/47d81956/attachment.html>


More information about the Chchrobotics mailing list