添加毛刺过滤算法,去除基线漂移算法
This commit is contained in:
@@ -84,5 +84,6 @@
|
|||||||
解决特定情况下导出方案文件名日期不对的问题
|
解决特定情况下导出方案文件名日期不对的问题
|
||||||
2023.10.20
|
2023.10.20
|
||||||
分析工具添加导出数据和分析结果html文件
|
分析工具添加导出数据和分析结果html文件
|
||||||
|
2023.10.22
|
||||||
|
添加毛刺过滤算法,去除基线漂移算法
|
||||||
|
|
||||||
|
@@ -189,7 +189,9 @@ class Analysis(QWidget):
|
|||||||
def import_but_clicked(self):
|
def import_but_clicked(self):
|
||||||
self.sch_data=scheme_data.sch_data()
|
self.sch_data=scheme_data.sch_data()
|
||||||
self.__import_but.setEnabled(False)
|
self.__import_but.setEnabled(False)
|
||||||
self.sch_data.select_scheme()
|
ack=self.sch_data.select_scheme()
|
||||||
|
if(ack!=True):
|
||||||
|
return
|
||||||
self._save_path="file/"+self.sch_data.scheme_name.split('/')[-1].split('.')[0]
|
self._save_path="file/"+self.sch_data.scheme_name.split('/')[-1].split('.')[0]
|
||||||
print(self._save_path)
|
print(self._save_path)
|
||||||
self.recv_data()
|
self.recv_data()
|
||||||
|
@@ -7,7 +7,7 @@ plt.rcParams['font.sans-serif']=['SimHei']
|
|||||||
plt.rcParams['axes.unicode_minus']=False
|
plt.rcParams['axes.unicode_minus']=False
|
||||||
|
|
||||||
|
|
||||||
x=np.arange(0,np.pi,0.01)
|
x=np.arange(0,np.pi,0.0025)
|
||||||
y=np.sin(x)*0.5
|
y=np.sin(x)*0.5
|
||||||
|
|
||||||
|
|
||||||
@@ -15,12 +15,21 @@ y=np.sin(x)*0.5
|
|||||||
def add_line(x):
|
def add_line(x):
|
||||||
ret=[]
|
ret=[]
|
||||||
length=len(x)
|
length=len(x)
|
||||||
num=length//10
|
num=length//40
|
||||||
index=0
|
index=0
|
||||||
|
t_old=0
|
||||||
for i in x:
|
for i in x:
|
||||||
t=(index//num)
|
t=(index//num)
|
||||||
|
if(t_old!=t):
|
||||||
|
h=np.random.random_sample()
|
||||||
|
t_old=t
|
||||||
if((t&1)!=0):
|
if((t&1)!=0):
|
||||||
ret.append(0.1*t)
|
t=index%num
|
||||||
|
if(t<(num//2)):
|
||||||
|
ret.append(((0.15+h)/num)*(index%num))
|
||||||
|
else:
|
||||||
|
ret.append(((0.15+h)/num)*(num-index%num))
|
||||||
|
# ret.append(0.15+((h)))
|
||||||
else:
|
else:
|
||||||
ret.append(0)
|
ret.append(0)
|
||||||
index+=1
|
index+=1
|
||||||
@@ -32,7 +41,7 @@ def add_random(x):
|
|||||||
ret=[]
|
ret=[]
|
||||||
length=len(x)
|
length=len(x)
|
||||||
index_table=[]
|
index_table=[]
|
||||||
for i in range(10):
|
for i in range(20):
|
||||||
index_table.append(int(np.random.random_sample()*10000%length))
|
index_table.append(int(np.random.random_sample()*10000%length))
|
||||||
# print(index_table)
|
# print(index_table)
|
||||||
for i in range(length):
|
for i in range(length):
|
||||||
@@ -42,33 +51,6 @@ def add_random(x):
|
|||||||
ret.append(x[i])
|
ret.append(x[i])
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# 滤波
|
|
||||||
def my_filter(x):
|
|
||||||
ret=[]
|
|
||||||
sub=[]
|
|
||||||
temp=np.sum(x[0:10])/10
|
|
||||||
t=0
|
|
||||||
t_p=0
|
|
||||||
k=0.005
|
|
||||||
signal=False
|
|
||||||
for i in x:
|
|
||||||
t_p=t
|
|
||||||
# t=t*0.9+i*0.1
|
|
||||||
t=temp
|
|
||||||
temp=(temp*9+i)/10
|
|
||||||
t_p=t-t_p
|
|
||||||
if(t_p>k):
|
|
||||||
signal=True
|
|
||||||
elif(t_p<-k):
|
|
||||||
signal=False
|
|
||||||
if(signal):
|
|
||||||
ret.append(0.3)
|
|
||||||
else:
|
|
||||||
ret.append(0)
|
|
||||||
sub.append(t_p)
|
|
||||||
return ret,sub
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 卡尔曼
|
# 卡尔曼
|
||||||
class kalman:
|
class kalman:
|
||||||
@@ -77,7 +59,8 @@ class kalman:
|
|||||||
out=0# 输出值
|
out=0# 输出值
|
||||||
Kg=0#卡尔曼增益
|
Kg=0#卡尔曼增益
|
||||||
Q=0.001# 过程噪声协方差
|
Q=0.001# 过程噪声协方差
|
||||||
R=.0543# 观测噪声协方差
|
# R=.0543# 观测噪声协方差
|
||||||
|
R=.00543# 观测噪声协方差
|
||||||
def calc(self,value:int):
|
def calc(self,value:int):
|
||||||
self.Now_P=self.LastP+self.Q
|
self.Now_P=self.LastP+self.Q
|
||||||
self.Kg=self.Now_P/(self.Now_P+self.R)
|
self.Kg=self.Now_P/(self.Now_P+self.R)
|
||||||
@@ -91,8 +74,131 @@ def my_kalman(x):
|
|||||||
ret.append(k.calc(i))
|
ret.append(k.calc(i))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
# 1阶低通滤波
|
||||||
|
def rc_low(x):
|
||||||
|
a=0.6
|
||||||
|
old=0
|
||||||
|
ret=[]
|
||||||
|
for i in x:
|
||||||
|
t=a*old+(1-a)*i
|
||||||
|
old=t
|
||||||
|
ret.append(t)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
# 求导
|
||||||
|
def der(x):
|
||||||
|
old=0
|
||||||
|
ret=[]
|
||||||
|
for i in x:
|
||||||
|
t=i-old
|
||||||
|
old=i
|
||||||
|
ret.append(t)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
# 滤波,过滤毛刺
|
||||||
|
def my_filter(x):
|
||||||
|
ret=[]
|
||||||
|
sub=[]
|
||||||
|
last=0
|
||||||
|
index=0
|
||||||
|
for i in x:
|
||||||
|
cat=x[index:index+10]
|
||||||
|
index+=1
|
||||||
|
lenth=len(cat)
|
||||||
|
if(lenth<10):
|
||||||
|
ret.append(0)
|
||||||
|
sub.append(0)
|
||||||
|
continue
|
||||||
|
temp=np.sort(cat)
|
||||||
|
head=np.average(cat[:lenth//2])
|
||||||
|
tail=np.average(cat[lenth//2:])
|
||||||
|
if((temp[lenth//2+1]-temp[lenth//2-1])>0.1):
|
||||||
|
if(head>tail):
|
||||||
|
last=0
|
||||||
|
else:
|
||||||
|
last=0.3
|
||||||
|
ret.append(last)
|
||||||
|
sub.append(0)
|
||||||
|
return ret,sub
|
||||||
|
|
||||||
|
|
||||||
|
# 滤波,三角变形
|
||||||
|
def my_filter2(x):
|
||||||
|
def limit(x):
|
||||||
|
x*=10
|
||||||
|
if(x>0.5):
|
||||||
|
return 0.5
|
||||||
|
elif(x<0):
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return x
|
||||||
|
ret=[]
|
||||||
|
sub=[]
|
||||||
|
last=0
|
||||||
|
index=0
|
||||||
|
old=0
|
||||||
|
for i in x:
|
||||||
|
index+=1
|
||||||
|
t=i-old
|
||||||
|
old=i
|
||||||
|
if(t>0.001):
|
||||||
|
last=0.3
|
||||||
|
elif(t>0.001):
|
||||||
|
last=0
|
||||||
|
ret.append(last)
|
||||||
|
sub.append(limit(t))
|
||||||
|
return ret,sub
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 只滤除毛刺
|
||||||
|
def my_burr(x):
|
||||||
|
ret=[]
|
||||||
|
last=0
|
||||||
|
index=0
|
||||||
|
for i in x:
|
||||||
|
cat=x[index:index+10]
|
||||||
|
index+=1
|
||||||
|
lenth=len(cat)
|
||||||
|
if(lenth<10):
|
||||||
|
ret.append(0)
|
||||||
|
continue
|
||||||
|
temp=np.sort(cat)
|
||||||
|
ret.append(temp[5])
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 去除基线漂移
|
||||||
|
def my_filter3(x):
|
||||||
|
x_burr=my_burr(x)
|
||||||
|
x_burr=rc_low(x_burr)
|
||||||
|
# ker=my_kalman(x_burr)
|
||||||
|
x2=der(x_burr)
|
||||||
|
x3=my_burr(x2)
|
||||||
|
ret=[]
|
||||||
|
last=0
|
||||||
|
index=0
|
||||||
|
signal=False
|
||||||
|
for i in x_burr:
|
||||||
|
if((x2[index]>=0.004)):
|
||||||
|
signal=True
|
||||||
|
elif((x2[index]<=-0.1)):
|
||||||
|
signal=False
|
||||||
|
if(signal==False):
|
||||||
|
last=i
|
||||||
|
index+=1
|
||||||
|
ret.append(i-last)
|
||||||
|
return np.multiply(x3,10),np.add(ret,0.3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
y2=add_random(y)
|
y2=add_random(y)
|
||||||
y3,y4=my_filter(y)
|
y3,y4=my_filter3(y2)
|
||||||
|
|
||||||
def show_xy(xy_list:list):
|
def show_xy(xy_list:list):
|
||||||
figure = plt.figure(figsize=(14,7))
|
figure = plt.figure(figsize=(14,7))
|
||||||
@@ -104,4 +210,4 @@ def show_xy(xy_list:list):
|
|||||||
ax.legend()
|
ax.legend()
|
||||||
index+=1
|
index+=1
|
||||||
plt.show()
|
plt.show()
|
||||||
show_xy([(x,y),(x,y3),(x,y4)])
|
show_xy([(x,y2),(x,y3),(x,y4)])
|
||||||
|
@@ -223,10 +223,10 @@ class sch_data(object):
|
|||||||
def select_scheme(self):
|
def select_scheme(self):
|
||||||
fileName,fileType = QFileDialog.getOpenFileNames(None, "选取文件", os.getcwd(),
|
fileName,fileType = QFileDialog.getOpenFileNames(None, "选取文件", os.getcwd(),
|
||||||
"检测方案(*.json)")
|
"检测方案(*.json)")
|
||||||
self.scheme_name=fileName[0]
|
|
||||||
if(len(fileName)==0):
|
if(len(fileName)==0):
|
||||||
print("user cancelled.")
|
print("user cancelled.")
|
||||||
return False
|
return False
|
||||||
|
self.scheme_name=fileName[0]
|
||||||
print(fileName,fileType)
|
print(fileName,fileType)
|
||||||
info=_get_info()
|
info=_get_info()
|
||||||
quest=quest_text("请输入要获取数据的日期",info[3]+','+info[4])
|
quest=quest_text("请输入要获取数据的日期",info[3]+','+info[4])
|
||||||
|
Reference in New Issue
Block a user