我想知道Python中的Energyfor1-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))实施是否正确?
发布于 2016-06-06 14:17:02
您可以稍微简化代码:
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])https://stackoverflow.com/questions/37659422
复制相似问题