小波提取背景

用小波基估计背景信号

安装

不能直接安装:
pip install pywt
这是另外一个不同的库,如果不幸安装了,需要

pip uninstall pywt
pip uninstall PyWavelets

然后:

conda install PyWavelets
pip install PyWavelets

输出

在这里插入图片描述
在这里插入图片描述

添加背景信号


from pywt import wavedec,waverec
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(-100,100,50)
bg = 5
y = 50*np.exp(-t**2/(2*2^2)) +bg
plt.plot(t,y)

在这里插入图片描述

小波基估计背景

需要截去高频信息,然后用小波基估计出背景信号

iter = 10
x_filt = y
th = 1
for i in range(iter):
     #wavelet transform

    coeffs = wavedec(x_filt,'db6',level=5)
    cA = coeffs[0]
    cD =  []
    # 令高频信息为0,也就是令cDn全部设置为0
    for j in range(1,len(coeffs)):     
         a = np.squeeze( np.array([np.zeros([np.size(coeffs[j]),1 ])]) )
         cD.append(a)  
    cD.insert(0,cA)

    # inverse wavelet transform by only using low-freq components  
    x_new = waverec(cD, 'db6')
    if th > 0:
    # cut off values over current estimated background level.
        eps = np.sqrt(abs(x_filt))/2
        ind = y > (x_new + eps)
        x_filt[ind] = x_new[ind]+eps[ind]
        
        # re-estimate background 
        coeffs = wavedec(x_filt,'db6',level=5)
        cA = coeffs[0]
        cD =  []
        for j in range(1,len(coeffs)):     #排除cA5,cDn全部设置为0
             a = np.squeeze( np.array([np.zeros([np.size(coeffs[j]),1 ])]) )
             cD.append(a)  
        cD.insert(0,cA)

        x_new = waverec(cD, 'db6')

在这里插入图片描述
黄色的点表示估计出来的背景

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值