0

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()
   

6
  • How to Ask and minimal reproducible example Commented Sep 19 at 9:17
  • "I am not getting any constant results" is not a clear enough description of your problem. Commented Sep 19 at 9:19
  • Well julien i have never worked with digital filters. Now the issue is that i am getting data from ADC and want to filter that data on the fly. Now here there are two approach of using IIR filter and FIR filter. To preserve phase lag or to remove phase delay FIR is good but this needs all the data and then it can filter whereas IIR filter can do it but i has phase delay or lag. So what kind of filter should i apply and how to apply that digital filter. Prepare the chunks of data and then filter or filter one data at a time ? Commented Sep 19 at 9:47
  • there is similar site for Raspberry Pi and there is official forum Raspberry Pi Commented Sep 19 at 11:27
  • 1
    Maybe first use print() (and print(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. Commented Sep 19 at 11:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.