MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

How to extract the dyadic wavelet coefficeints from the DWT (decimated) 'wavedec' function output

Asked by Terry on 2 Oct 2012

The coefficients output from the function 'wavedec' are the artifacts from the convolution of the input signal (vector) and the wavelet/scale functions. Thus the length of the coefficients from any scale is a function of the lengths of the wavelet/scale functions and the dyadic of the signal at the level being decomposed. As an example if the input signal is 64 samples long and a Daubechies wavelet with four vanishing moments is used (db4) then the lengths of the coefficients produced are 7,7,8,10,14,21, and 35 for ca1, cd1, cd2, ….. cd6. The actual lengths should be 1,1,2,4,8,16, and 32. This can be verified by performing the decomposition manually without convolution, ie using the’ sumproduct’ function with the proper wavelet/scale function in Excel for instance. How then do you select the dyadic coefficients from the output from ‘wavedec”? Sometimes is looks like taking the middle n coefficients for high numbered levels works and sometimes it looks like taking the last n coefficients works for low numbered levels. What’s up?s

added note: The dwtmode was 'sym' for the above discussion. When dwtmode = 'per' the dyadic coefficients result. Modify the question to mean for modes other than 'per'

Products

Answer by Wayne King on 2 Oct 2012
Edited by Wayne King on 2 Oct 2012

You can set the dwtmode to 'per' and then use detcoef() or appcoef()

```   dwtmode('per')
x = randn(1024,1);
[C,L] = wavedec(x,4,'db4');
d1 = detcoef(C,L,1);```

To get all the detail coefficients in a cell array

`   det = detcoef(C,L,'cells');`

Or you can do something like:

```[d1,d2,d3,d4] = detcoef(C,L,[1 2 3 4]);
```

1 Comment

Terry on 4 Oct 2012

Thanks for the reply but the question was really about the coefficients from decompositions from extended signals that do not have dyadic lengths. Sorry for the confusion. I added the note at the bottom after publishing to clarify.

After some thought I am wondering what the consequence is for applying a windowing function like a Blackman or other that will force stationarity on the signal and remove the edge effects from the wavelet transform. I suppose there will be some price to pay and it may be worse than doing nothing.