Python中一维小波的能量

2024-09-28 22:25:19 发布

您现在位置:Python中文网/ 问答频道 /正文



我想知道在Python中是否有一个一维小波能量的实现,与Matlab的'[Ea,Ed]=wenergy(C,L)'相同。 我试着自己写一篇,但我不确定: 公式为:

enter image description here

其中Dj是细节向量,j=1,2,…,ld和N1是分解层的数据长度。在

import json
import pywt
f=open('DataFile.txt','r')
D=json.load(f)
f.close()
#create the wavelet function
db1 = pywt.Wavelet('db13')
#calculate the number of necessary decompositions
NbrDecomp= pywt.dwt_max_level(len(D), db1)+1
#Initialize an empty list to receive the Detail and Approximation
Vector = [None] * NbrDecomp
#we use the Wavelet decomposition in the pywt module 
Vector = pywt.wavedec(D, db1)
#Now Vector = [Approxiamtion N, Details N, Details N-1,.....] 
#Where N would be the number of decompositions

根据定义,k级能量为:

^{pr2}$

实施是否正确?在


Tags: oftheimportjsonnumberdetails能量vector
1条回答
网友
1楼 · 发布于 2024-09-28 22:25:19

您可以稍微简化代码:

coeffs[len(coeffs) - k - 1]

可以重写为

^{pr2}$

您可以将平方和求和作为一个NumPy操作来执行(因为您已经在使用NumPy了)

def Energy(coeffs, k):
    return np.sqrt(np.sum(np.array(coeffs[-k]) ** 2)) / len(coeffs[-k])

相关问题 更多 >