Below is my python code for fetching data from ADS1263. The ic has been configured properly and i am getting the data. I want to filter the data on the fly or you can say fetch one data and filter it and print it on the screen. I am trying to apply low pass butter filter but i am not getting any constant results.
Can somebody guide me how to apply filter to the new data, one data at a time ?
import time
import ADS1263
import RPi.GPIO as GPIO
import statistics
from scipy.signal import butter, sosfiltfilt
from scipy.signal import firwin, filtfilt
fs = 20.0 # Sampling frequency (Hz)
fc = 0.05 # Cutoff frequency (Hz)
order1 = 3 # You may need a large order for such a low cutoff
fir_coef = firwin(order1+1, fc/(fs/2), window='hamming')
order = 5
sos = butter(order, fc/(fs/2), btype='low', output='sos')
my_index = 0
my_list = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
try:
ADC = ADS1263.ADS1263()
#Config ADC for Differential Measurement
ADC.ADS_1263_Get_Registers()
#Start ADC
ADC.ADS1263_WriteCmd(0x08)
while(1):
ADC.ADS1263_WaitDRDY()
value = ADC.ADS1263_Read_ADC_Data()
if(value & 0x80000000):
value |= 0xff000000
value1 = (value * (2.0 * 5.080) ) / ( 32 * 4294967296.0 )
value1 = value1 * 1000;
if my_index < 19:
my_list[my_index] = value1
my_index = my_index + 1
else:
my_list[my_index] = value1
filtered_signal = sosfiltfilt(sos, my_list)
_mean = filtered_signal[-1]
print("mV = %0.5lf" %(_mean))
my_index = 0
for i in range(19):
my_list[i] = my_list[i+1]
ADC.ADS1263_Exit()
except IOError as e:
print(e)
except KeyboardInterrupt:
print("ctrl + c:")
print("Program end")
ADC.ADS1263_Exit()
exit()
print()
(andprint(type(...))
,print(len(...))
, etc.) to see which part of code is executed and what you really have in variables. It is called"print debugging"
and it helps to see what code is really doing.