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'
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]);