Acceleration - bandpass filter

frohr

Well-known member
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/2016/03/arduino-tutorial-simple-high-pass-band-pass-and-band-stop-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
 
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.
 
Audio library

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 ?
 
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.
 
Back
Top