Dear Hai, I would first ask. Are you sure you need the CWT here and not the MODWT? The MODWT is limited to dyadic scales (that is a limitation as opposed to CWT), but it has the property that it allows for perfect reconstruction (perfect inversion) and it allows you to obtain a reconstruction (projection) of the signal onto each scale with MODWTMRA.
The MODWT and associated functionality work with orthogonal wavelets -- the Haar is one such wavelet.
dt = 1/180;
t = 0:dt:(length(wecg)*dt)-dt;
wtecg = modwt(wecg,3,'haar');
ecgmra = modwtmra(wtecg,'haar');
plot(t,wecg); title('Original Data');
for kk = 1:size(ecgmra,1)
The top plot is the original signal, the first plot is the projection onto the wavelet (detail) subspace corresponding to a scale of 2 (the highest resolution or shortest scale), the next is the projection onto the wavelet subspace of scale 4, and finally the last row is the projection onto the scaling (lowpass) space at scale 2^3=8
If you sum the rows of ecgmra (summing the MODWT MRA at each time point), you will get back the original signal.
ts = sum(ecgmra,1);