Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Acceleration - bandpass filter

  1. #1
    Member
    Join Date
    Nov 2020
    Location
    Czech Republic
    Posts
    49

    Acceleration - bandpass filter

    Hi all,
    I am reading samples from ADXL via ADC (Teensy 4). I have it in buffer and then I need apply bandpass filter to calculate acceleration for 500-7500Hz and for velocity for 10-1000Hz. Anybody knows code for this type of bandpass filter?
    I am trying this but no clue if is it correct. I am testing it with signal generator, sine wave. For example when I set 300Hz and 0,02V RMS I can see 0,8gRMS and if I set 2000Hz I can see 0,6gRMS. (gRMS = pow(every sample from ADC,2) then sqrt of sum). In my opinion, if I set 2000Hz sine then I have to see near zero gRMS, right?

    https://www.norwegiancreations.com/2...top-filtering/

    Code:
      float EMA_a_low = 0.001;  //10Hz
      float EMA_a_high = 0.3;   //500Hz
      float EMA_S_low = 0;      
      float EMA_S_high = 0;
      float highpass = 0;
      float bandpass = 0;
    
    for (k = 0 ; k < TOTAL_SAMPLES; k++)
      {
      g = data_from_adc[k];
      EMA_S_low = (EMA_a_low*g) + ((1-EMA_a_low)*EMA_S_low);  
      EMA_S_high = (EMA_a_high*g) + ((1-EMA_a_high)*EMA_S_high);
      highpass = g - EMA_S_low;    
      g_buffer[counter] = EMA_S_high - EMA_S_low;    
    }
    Thanks
    Michal

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,235
    A wide-range bandpass filter is easiest to realize as a high-pass filter and a low-pass filter chained together.
    Can you generate Butterworth low-pass and high-pass filters? There are many on-line apps to help with this.

  3. #3
    Senior Member
    Join Date
    Sep 2015
    Posts
    102

    Audio library

    Quote Originally Posted by MarkT View Post
    A wide-range bandpass filter is easiest to realize as a high-pass filter and a low-pass filter chained together.
    Can you generate Butterworth low-pass and high-pass filters? There are many on-line apps to help with this.
    Sorry, just passing through,
    this is well in the audio range,
    and i seem to remember Tensey has a great set of audio libraries,

    would these not be the way forward ?

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,235
    Indeed, and if you use this you'd implement the various filter sections using the AudioFilterBiquad class,
    but first you have to generate the filter coefficients - the original code just uses first-order sections which
    isn't precise at all in the frequency domain.

    With the audio library you could alternative use an FFT and sum the relevant buckets.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •