+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Junior Member level 2
    Points: 167, Level: 2

    Join Date
    Aug 2012
    Posts
    20
    Helped
    1 / 1
    Points
    167
    Level
    2

    filtering adc samples using stm32

    Hi all,

    I am acquiring adc voltage using stm32 device and after 1000 samples I am doing the mean value but I have found that this is not sufficient in my case (the value (average) I got is not stable) I thought to increase the number of samples (size of buffer) but I face RAM size issue so I want to know is there some other method to have a stable value other than averaging ?

    MCU Lüfter

    •   Alt15th August 2012, 13:29

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 12,648, Level: 26
    Achievements:
    7 years registered

    Join Date
    Nov 2008
    Location
    Norwich, UK
    Posts
    2,122
    Helped
    598 / 598
    Points
    12,648
    Level
    26

    Re: filtering adc samples using stm32

    have you tried a running average? also zeroing the least significant bits of the ADC value?
    have you looked at your signal with an oscilloscope? have you a lot of noise or could you be aliasing?



    •   Alt15th August 2012, 13:44

      advertising

        
       

  3. #3
    Member level 1
    Points: 347, Level: 3

    Join Date
    Jul 2012
    Posts
    41
    Helped
    3 / 3
    Points
    347
    Level
    3

    Re: filtering adc samples using stm32

    Instead of storing the samples, why don't you sum the Sample using a counter and then divide per the value of the counter ? If you want to calculate the mean of 5000 samples, you use a variable used to sum each sample at the sampling rate and then (you count the samples with a counter) and then you divide the sum per the value of your counter.



    •   Alt15th August 2012, 14:42

      advertising

        
       

  4. #4
    Junior Member level 2
    Points: 167, Level: 2

    Join Date
    Aug 2012
    Posts
    20
    Helped
    1 / 1
    Points
    167
    Level
    2

    Re: filtering adc samples using stm32

    Hi guetguet,

    because I am using the ARM library, I'll try to test my code as you said and I'll keep you informed.
    @horace I tested with zeroing the LSB but w/o success, I didn't find in ARM DSP library running (moving) average algorithm.

    MCU Lüfter



  5. #5
    Advanced Member level 5
    Points: 16,636, Level: 31

    Join Date
    Jul 2001
    Location
    Oberon
    Posts
    1,897
    Helped
    439 / 439
    Points
    16,636
    Level
    31

    Re: filtering adc samples using stm32

    I read this somewhere and saved it. How to implement a simple single pole digital filter. It works great and I now use it all the time.

    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.



    •   Alt15th August 2012, 15:07

      advertising

        
       

  6. #6
    Member level 1
    Points: 347, Level: 3

    Join Date
    Jul 2012
    Posts
    41
    Helped
    3 / 3
    Points
    347
    Level
    3

    Re: filtering adc samples using stm32

    So try to change a little the code of ARM, it will be pretty easy



--[[ ]]--