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设计】。

相关文章

Pytorch根据layers的name冻结训练方式

使用model.named_parameters()可以轻松搞定, model.cuda() # ######################################...

python实现模拟按键,自动翻页看u17漫画

python 适用于windows平台 使用 win32gui,win32api,win32con 包 simu_read.py 复制代码 代码如下: #-*- coding=utf-...

Appium+python自动化怎么查看程序所占端口号和IP

Appium+python自动化怎么查看程序所占端口号和IP

简介 这篇博文和分类看似没有多大关系,但是也是从上一篇衍生出来的产物,因为涉及到 FQ工具 Lantern ,就算是给关注和支持的小伙伴们拓展一下眼界和知识面。而且好多人都阅读了上一篇...

python字典键值对的添加和遍历方法

添加键值对 首先定义一个空字典 >>> dic={} 直接对字典中不存在的key进行赋值来添加 >>> dic['name']='zhangsan...

把大数据数字口语化(python与js)两种实现

python 复制代码 代码如下:def fn(num):    '''    把数字口语化   ...