ECG心电信号处理-FIR

防止边界值突变可以使用边界值重复

class filter:
    def __init__(self,order,h):
        self.order=order
        self.h=h
        self.output=[]
    def FIR_Filter(self,vi):
        for i in range(len(vi)):
            sum=0
            if i < self.order:
                for j in range(i):
                    sum=sum + self.h[j]*vi[i-j]
            else:      
                for j in range(self.order):
                    sum=sum + self.h[j]*vi[i-j]
                
            self.output.append(sum)   
        return self.output

def read_data_to_list():
    fo = open("心电.txt", mode = "rt")
    x = []
    for line in fo.readlines():
        line =  line.strip('\n')
        x.append(eval(line))
    fo.close()
    return x
def file_to_fir_head():
    fir_head = open("抽头.txt",mode='rt')
    data_file = fir_head.read()
    data=[]
    data_file = data_file.split('\t')
    for i in map(eval,data_file):
        data.append(i)
    fir_head.close()
    return data

import matplotlib.pyplot as plt

#原始数据
plt.subplot(2,2,1)
plt.title("orgin")
hear_data = read_data_to_list()
plt.plot(hear_data)


#fir抽头
plt.subplot(2,2,2)
plt.title("fir_head")
head = file_to_fir_head()
plt.plot( head  )

#fir处理
plt.subplot(2,2,3)
plt.title("no_rim_copy_to_fir")
head = file_to_fir_head()
fir = filter(61 ,head )
fir.FIR_Filter(hear_data)
plt.plot( fir.output  )


#边界重复后fir处理
plt.subplot(2,2,4)
plt.title("rim_copy_to_fir")
head = file_to_fir_head()
fir = filter(61 ,head )
new_hear_data = []
for i in range(61):
    new_hear_data.append(hear_data[0])
for i in hear_data:
    new_hear_data.append( i )
fir.FIR_Filter(new_hear_data)
fir_out_put = fir.output[61:]
plt.plot( fir_out_put )

plt.show()

在这里插入图片描述

文件可以看我的资源
在这里插入图片描述
放一张用其他数据来测试的图片
在这里插入图片描述

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

酸奶可乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值