Python Pywavelet 小波阈值实例

yipeiwu_com6年前Python基础

小波应用比较广泛,近期想使用其去噪。由于网上都是matlib实现,故记下一下Python的使用

Pywavelet  Denoising 小波去噪 

# -*- coding: utf-8 -*-
 
import numpy as np
import pywt
 
data = np.linspace(1, 4, 7)
 
# pywt.threshold方法讲解:
#    pywt.threshold(data,value,mode ='soft',substitute = 0 )
#    data:数据集,value:阈值,mode:比较模式默认soft,substitute:替代值,默认0,float类型
 
#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]
#output:[ 6. 6. 0. 0.5 1. 1.5 2. ]
#soft 因为data中1小于2,所以使用6替换,因为data中第二个1.5小于2也被替换,2不小于2所以使用当前值减去2,,2.5大于2,所以2.5-2=0.5.....
print "---------------------soft:绝对值-------------------------"
print pywt.threshold(data, 2, 'soft',6)
 
print "---------------------hard:绝对值-------------------------"
 
#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]
#hard data中绝对值小于阈值2的替换为6,大于2的不替换
print pywt.threshold(data, 2, 'hard',6)
 
print "---------------------greater-------------------------"
 
#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]
#data中数值小于阈值的替换为6,大于等于的不替换
print pywt.threshold(data, 2, 'greater',6)
print "---------------------less-------------------------"
print data
#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]
#data中数值大于阈值的,替换为6
print pywt.threshold(data, 2, 'less',6)

参考官方文档地址:https://pywavelets.readthedocs.io/en/latest/ref/thresholding-functions.html

以上这篇Python Pywavelet 小波阈值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

各个系统下的Python解释器相关安装方法

Python下载 Python最新源码,二进制文档,新闻资讯等可以在Python的官网查看到: Python官网:http://www.python.org/ 你可以在一下链接中下载Py...

Python实现二叉搜索树

Python实现二叉搜索树

二叉搜索树 我们已经知道了在一个集合中获取键值对的两种不同的方法。回忆一下这些集合是如何实现ADT(抽象数据类型)MAP的。我们讨论两种ADT MAP的实现方式,基于列表的二分查找和哈...

numpy返回array中元素的index方法

如下所示: import numpy a = numpy.array(([3,2,1],[2,5,7],[4,7,8])) itemindex = numpy.argwhere(a...

python几种常用功能实现代码实例

这篇文章主要介绍了python几种常用功能实现代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1、python 程序退出的几种...

在Python中预先初始化列表内容和长度的实现

如果想设置相同的初值和想要的长度 >>> a=[None]*4 >>> print(a) [None, None, None, None] 如果...