Simple Low Pass Filter in C - Page 1
Forum section: electronics / general

author: aiq25
author_rank: Regular Contributor
timestamp: May 30, 2017, 07:46:59 pm
content: 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-applicationsI 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_smoothingThanks!

author: hamster_nz
author_rank: Super Contributor
timestamp: May 30, 2017, 11:38:53 pm
content: 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.

author: aiq25
author_rank: Regular Contributor
timestamp: May 31, 2017, 03:49:16 am
content: Quote from: hamster_nz on May 30, 2017, 11:38:53 pmThanks. 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.

author: danadak
author_rank: Super Contributor
timestamp: May 31, 2017, 11:08:12 am
content: In case you wanted to do this in HW as a background task, PSOC,see attached.Regards, Dana.

author: stfsux
author_rank: Contributor
timestamp: May 31, 2017, 12:43:05 pm
content: I've already used those PSOC and I'm still amazed by their analog features.

author: Dielectric
author_rank: Regular Contributor
timestamp: June 01, 2017, 02:55:11 pm
content: 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.

author: aiq25
author_rank: Regular Contributor
timestamp: June 01, 2017, 07:12:54 pm
content: Quote from: Dielectric on June 01, 2017, 02:55:11 pmYes, this is for reading a sensor output. The sensor itself has a very slow response time.

author: hamster_nz
author_rank: Super Contributor
timestamp: June 01, 2017, 08:41:31 pm
content: Quote from: aiq25 on June 01, 2017, 07:12:54 pmAs 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.