Recent

Author Topic: lowpass filter  (Read 2089 times)

coradi

  • Full Member
  • ***
  • Posts: 197
lowpass filter
« on: August 18, 2021, 11:14:07 am »
Does anybody have working code(im Beginner) for an lowpass filter?
I need this for my Mikro Pascal Projekt for ADC Measurement
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

Zvoni

  • Hero Member
  • *****
  • Posts: 3370
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

dseligo

  • Hero Member
  • *****
  • Posts: 1683
Re: lowpass filter
« Reply #2 on: August 18, 2021, 11:31:18 am »
https://forum.lazarus.freepascal.org/index.php?topic=15412.0

Link in the post (http://www.antillasoft.com/) doesn't work, user AntillaSoft was last active in 2013.
Maybe someone has copy of components?

Zvoni

  • Hero Member
  • *****
  • Posts: 3370
Re: lowpass filter
« Reply #3 on: August 18, 2021, 11:50:40 am »
Did you have a look in OPM?
I'm currently at work, and we've restricted Internet-Access (cannot access OPM-Repo)

EDIT: https://github.com/jakobsche/equalizer
« Last Edit: August 18, 2021, 11:52:54 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

avra

  • Hero Member
  • *****
  • Posts: 2586
    • Additional info
Re: lowpass filter
« Reply #4 on: August 18, 2021, 01:35:59 pm »
Does anybody have working code(im Beginner) for an lowpass filter?

Here is one in MikroC. Shouldn't be too hard to adapt to MikroPascal.
https://libstock.mikroe.com/projects/view/252/digital-low-pass-filtering-or-how-to-add-more-bits-of-resolution-to-an-adc

If simple integrator for smoothing the signal is enough then maybe this will work:
Code: Pascal  [Select][+][-]
  1. function SimpleIntegrate(const OldVal, NewVal: float; const factor: byte): float;
  2. var
  3.   x: float;
  4. begin
  5.   x := (OldVal * factor) + NewVal;
  6.   Result := x / (factor + 1);
  7. end;
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Thaddy

  • Hero Member
  • *****
  • Posts: 19143
  • Glad to be alive.
objects are fine constructs. You can even initialize them with constructors.

Nitorami

  • Hero Member
  • *****
  • Posts: 605
Re: lowpass filter
« Reply #6 on: August 18, 2021, 03:22:21 pm »
For tasks like smoothing ADC values I would suggest something very simple like

Code: Pascal  [Select][+][-]
  1. xout := xout*k + xin*(1-k);
  2.  

where xin is the next input value from the ADC and xout is your smoothed output. Just repeat this for each sample from the ADC. 
k is a fixed value in the range 0...1. The closer k is to 1, the slower the output will follow the input.

avra

  • Hero Member
  • *****
  • Posts: 2586
    • Additional info
Re: lowpass filter
« Reply #7 on: August 18, 2021, 03:33:33 pm »
For tasks like smoothing ADC values I would suggest something very simple like

Code: Pascal  [Select][+][-]
  1. xout := xout*k + xin*(1-k);
That is just a variation of SimpleIntegrate() function, which was not written as a one liner for the sake of clarity. I prefer SimpleIntegrate() form because it is very clear that if you feed the function with the same NewVal for factor number of iterations, result will reach the value of NewVal.
« Last Edit: August 18, 2021, 03:35:19 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018