Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple digital filter for A/D conversions

Status
Not open for further replies.

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,896
Helped
438
Reputation
880
Reaction score
288
Trophy points
1,363
Location
Oberon
Activity points
12,887
Many systems use an ADC to sample analog data that temperature and pressure sensors produce.
Sometimes, system noise or other factors cause the otherwise slowly fluctuating data to "jump around." To reduce higher frequency noise, designers often install an analog RC (resistor-capacitor) lowpass filter between the sensor and the analog-to-digital-conversion stage. However, this approach is not always ideal or practical. A long time constant of minutes would require very large values for R and C.
An analog RC lowpass filter's turnover frequency or cutoff frequency (in hertz), is determined by the time constant of R in Ohms and C in Farads.
Frequ. = 1 / (2 * Pi * R * C).

As an alternative, you can clean up noisy signals that remain within the ADC's linear range by using the digital equivalent of an analog RC lowpass filter.
The filter's software comprises only two lines of C code:

LPOUT = LPACC / K

where the output value of the filter is LPACC divided by a constant, and

LPACC = LPACC + LPIN - LPOUT

where you add the difference between input and output to update LPACC.
You specify all variables as integers.
Each time the analog-to-digital conversion acquires a new input sample, LPIN, the software produces an output value, LPOUT, which comprises a lowpass-filtered version of the input samples.
Calculate the value of the constant, K, based on the sampling rate of the system and the desired time constant for the filter as follows:

K = T × SPS

where K > 1, and SPS is the system's sampling rate.

For example, for a system-sampling rate of 200 samples/sec and a desired time constant of 30 sec, the constant K would equal 6000 samples.
Applying a step change to the routine's input requires 6000 samples to reach approximately 63% of its final value at the output.

The lowpass accumulator, LPACC, can grow large for large time constants and large input values. It can grow as large as K times the largest possible LPIN value. Under these conditions, you need to make sure that LPACC does not overflow, and you may need to specify a larger data type to contain LPACC.
To avoid a long settling time during start-up, before the start of the sampling loop, you can initialize LPACC to a value of K times the current input value.
 

Yes, it is a copy and paste. But this is useful information.
A common approach to this problem is to sum a number of samples and then take the average.
But I think this is a better solution.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top