Different filters for sensor data¶
Low pass filter for a list input¶
I.e. (acc_x, acc_y, acc_z)
ALPHA = 0.1
def lowPass( input, output ):
for i in range(0,len(input)):
output[i] = (input[i] * ALPHA) + (ouptut[i] * (1.0 - ALPHA))
return output
High Pass¶
ALPHA = 0.1
def highPass( input, gravity ):
output = []
for i in range(0,len(input)):
gravity[i] = (gravity[i]* ALPHA ) + (input[i] *(1-ALPHA))
output[i] = input[i] - gravity[i]
return output
Exponential Weighted Moving Average¶
ALPHA = 0.1
def average(raw_input, filtered_output):
for i in range(0, len(raw_input)):
filtered_output[i] = ALPHA*raw_input[i] + (1-ALPHA)*filtered_output[i-1]
return filtered_output