簡體   English   中英

Python中一維小波的能量

[英]Energy for 1-D wavelet in Python



我想知道是否有Python中的1-D小波能量實現,與Matlab'[Ea,Ed] = wenergy(C,L)'相同。 我試圖自己寫一個,但是我不確定:公式是:

在此處輸入圖片說明

其中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級能量為:

Energy(k)=np.sqrt(sum([x**2 for x in Vecktor[len(Vektor)-N-1-k]])/len(Vektor))

實施正確嗎?

您可以稍微簡化一下代碼:

coeffs[len(coeffs) - k - 1]

可以改寫成

coeffs[-k]

並且您可以將NumPy運算進行平方和求和(因為您已經在使用NumPy)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM