Author Topic: Simple Low Pass Filter in C  (Read 7332 times)

0 Members and 1 Guest are viewing this topic.

Offline aiq25Topic starter

  • Regular Contributor
  • *
  • Posts: 244
  • Country: us
Simple Low Pass Filter in C
« on: May 30, 2017, 07:46:59 pm »
Hello. I'm trying to implement a 2 minute time period LPF in C. I came across the following article: http://www.edn.com/design/systems-design/4320010/A-simple-software-lowpass-filter-suits-embedded-system-applications

I understand the article except the part for calculating the value for "k". It seems like "k" is related to the period/frequency of the LPF. The equation for this seems like a 1st order LPF. Can someone help explain how to relate the value of "k" to the timing period?

My guess is "k" is the time constant alpha from this article: https://en.m.wikipedia.org/wiki/Exponential_smoothing

Thanks!
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2862
  • Country: nz
Re: Simple Low Pass Filter in C
« Reply #1 on: May 30, 2017, 11:38:53 pm »
Read here....  http://www.dspguide.com/pdfbook.htm - everything you want will be there for free - esp chapter 10.

The very short answer is it depends on the sample rate of your data stream and the type/order of filter you are using.
« Last Edit: May 31, 2017, 12:54:19 am by hamster_nz »
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline aiq25Topic starter

  • Regular Contributor
  • *
  • Posts: 244
  • Country: us
Re: Simple Low Pass Filter in C
« Reply #2 on: May 31, 2017, 03:49:16 am »
Read here....  http://www.dspguide.com/pdfbook.htm - everything you want will be there for free - esp chapter 10.

The very short answer is it depends on the sample rate of your data stream and the type/order of filter you are using.

Thanks. I will have to read through the different chapters. Funny thing is I took DSP in college but seemed to have forgotten a lot of it.  :(

The type of filter is a first order low-pass (this much I can tell). Right now I'm sampling the signal at a rate of 100Hz.
 

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
Re: Simple Low Pass Filter in C
« Reply #3 on: May 31, 2017, 11:08:12 am »
In case you wanted to do this in HW as a background task, PSOC,
see attached.


Regards, Dana.
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 

Offline stfsux

  • Contributor
  • Posts: 23
  • Country: 00
Re: Simple Low Pass Filter in C
« Reply #4 on: May 31, 2017, 12:43:05 pm »
I've already used those PSOC and I'm still amazed by their analog features.
 

Offline Dielectric

  • Regular Contributor
  • *
  • Posts: 127
  • Country: 00
Re: Simple Low Pass Filter in C
« Reply #5 on: June 01, 2017, 02:55:11 pm »
I love PSoC and the DFB, but I'd still put that filter in as Code.  The bandwidth here is super low, not really in the sweet spot for the DFB (plus it takes a TON of current).

Are you sure about that two-minute figure?  Something that long makes me wonder if something like a smoothing filter combined with some level comparison (with hysteresis) code might be better.
 

Offline aiq25Topic starter

  • Regular Contributor
  • *
  • Posts: 244
  • Country: us
Re: Simple Low Pass Filter in C
« Reply #6 on: June 01, 2017, 07:12:54 pm »
Are you sure about that two-minute figure?  Something that long makes me wonder if something like a smoothing filter combined with some level comparison (with hysteresis) code might be better.

Yes, this is for reading a sensor output. The sensor itself has a very slow response time.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2862
  • Country: nz
Re: Simple Low Pass Filter in C
« Reply #7 on: June 01, 2017, 08:41:31 pm »
Yes, this is for reading a sensor output. The sensor itself has a very slow response time.

As the filter has a slow response time it sort of has a low pass filter inbuilt.

So is the question is "how is the best way I can remove noise from an ADC reading?"

If I didn't need a theoretical "best" result, I would just accumulate over 100 samples (one second).  Why one second? because then any 60Hz or 50Hz noise hum should be completely removed, or if your sampling clock is off (worst case is when it is off by a huge 1%) even then only about 1% of hum would be present.

If the sensor is super-slow in changing and noise levels are already low you will still get 'steps' in the output. One solution could be to actually add a couple of bits of noise to the signal to cause the LSBs to jump around, or another would be to get an ADC with higher resolution.



Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->