calibration_loader.py 文件源码

python
阅读 56 收藏 0 点赞 0 评论 0

项目:pslab-desktop-apps 作者: fossasia 项目源码 文件源码
def loadADCFile(self,filename,newLimits=[-30,30]):
            print ('Loading ',filename)
            INPUTNAME = filename.split('_')[1]
            GAIN = filename.split('_')[2].split('x')[0]

            data = np.loadtxt('%s/%s'%(self.dirname,filename))
            X=data[:,0];Y=data[:,1];
            source=self.analogInputSource(INPUTNAME)
            source.setGain(int(GAIN))
            X2=[];Y2=[]
            for B in range(len(X)):
                if source.__conservativeInRange__(X[B]) and X[B]>newLimits[0] and X[B]<newLimits[1]:
                    X2.append(X[B]);Y2.append(Y[B])
            X=np.array(X2);Y=np.array(Y2)
            RAW = source.voltToCode12(Y)                                #convert back to ADC codes for testing
            avg_shifts=(self.adc_shifts[np.int16(np.floor(RAW))]+self.adc_shifts[np.int16(np.ceil(RAW))])/2. # Find mean shift(in code units) of ADC INL at each code,
            # so it can be removed (Next line) , before calculating slope & intercept for the channel under process
            OFFSET_REMOVED = RAW-4095*(avg_shifts*self.INL_SLOPE - self.INL_INTERCEPT)/3.3  #apply calibration of the ADC. no slope correction yet. 
            #OFFSET_REMOVED = source.calPoly12(OFFSET_REMOVED)  #convert to voltage values

            fitvals = np.polyfit(OFFSET_REMOVED[1:],X[1:],3)
            self.results[INPUTNAME][int(GAIN)]=fitvals
            fitfn = np.poly1d(fitvals)
            print (filename,fitvals,fitfn(0),fitfn(4095))

            self.rawCurves[filename].setData(np.array(X),X-Y)
            self.cleanCurves[filename].setData(np.array(X),X-fitfn(OFFSET_REMOVED)) 
            #tmpfit = np.polyfit(X[1:],Y[1:],3)
            #tmppoly = np.poly1d(tmpfit)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号