0

I am new in the area of using wavelet decomposition. And I am trying to decompose and reconstruct (with very few coefficients) a 1D data in python (using pywt). From this documentation I wrote the code below which reconstructs the data with 512 coefficients (i.e. size of cA or cD) but I think their should be a way choosing (limiting) the number of coefficients that I consider to produce reasonable data reconstruction.

%matplotlib inline
import pylab as plt
import pywt

# Data
data = ll[5].x0

n = len(data)

w = 'db1'

(cA, cD) = pywt.dwt(data, w, 'sp1')  # Decomposition 

# Perfect Reconstruction of data
perfect_reconstruction = pywt.upcoef('a',cA[:],w,take=n) + pywt.upcoef('d',cD[:],w,take=n)
reconstructed = pywt.upcoef('a',cA[:],w,take=n) # Approximate Reconstruction of data

x = np.arange(1.008,1.008+1024*0.001,0.001)

plt.figure(figsize=(20,8))
plt.subplot2grid((2,1),(0,0)) 
plt.title('Perfect Reconstruction of data - %s  with rms error of 1.39 x e$^{-15}$'%w, fontsize=20)
plt.plot(x,data,'-',label='Data')

plt.plot(x,perfect_reconstruction,'-r',label='Reconstructed data')
plt.legend(loc='best',fontsize='x-large')
plt.xticks(fontsize = 14)
plt.yticks(fontsize = 14)

plt.subplot2grid((2,1),(1,0))
plt.title('Approximate Reconstruction of data - %s with rms error of 1.30 x e$^{-3}$'%w, fontsize=20)
plt.plot(x,data,'-',label='Data')

plt.plot(x,reconstructed,'-r',label='Reconstructed data')
plt.legend(loc='best',fontsize='x-large')
plt.xticks(fontsize = 14)
plt.yticks(fontsize = 14)
plt.show()

Figure 1 Please, if anyone can help me with any suggestions on what I can do to achieve proper decomposition and reconstruction with fewer coefficients I will highly appreciate it and any information on how to write the maths behind this because my goal is the to find a mathematical expression that best describes the data with fewer coefficients after deomposition.

Kela
  • 41
  • 6
  • Hey, did you manage to get this working? – MosesA Jul 27 '16 at 16:32
  • No, I've not got a solution for this yet. If you have any suggestion, I will highly appreciate it. – Kela Jul 28 '16 at 17:48
  • I ended up using Matlab's wavelet functions instead. They allow you to specify the level of decomposition you want. Reconstruction is a bit tricky though. I used DWT in periodic mode so is was easier to hack. – MosesA Aug 12 '16 at 11:57
  • Here's a link to my question. http://stackoverflow.com/q/38619008/1193534 – MosesA Aug 12 '16 at 12:01

0 Answers0