Implementation of Wavelet feature formula in MATLAB

Hi Mike,

I have written the following lines of code to extract the Wavelet feature (used in this article section 4.2.2) from the EEG signal. I used the Wavedec function of the Wavelet toolbox of the MATLAB to decompose the signal and get the details coefficients that correspond to different EEG bands. Then amplitude squared those coefficients to compute energy (which is called “Ej” in the mentioned paper) for theta band. I took mean across all the time-points to get one value for that band. Could you please confirm to me if the code is correct for computing the “Ej” value in the mentioned paper or not.

Note: the sampling rate of my input signal is 128 samples/sec that’s why I use level=4 in the wavedec function.

% single channel data
Data =,:)

% Multilevel 1-D wavelet decomposition

% 1-D detail coefficients
cD1 = detcoef(c,l,1); %NOISY 
cD2 = detcoef(c,l,2); %GAMMA 
cD3 = detcoef(c,l,3); %BETA 
cD4 = detcoef(c,l,4); %ALPHA 
cD5 = detcoef(c,l,5); %THETA 
cA5 = appcoef(c,l,waveletName,5); %DELTA

% wavelet coefficient energy for theta band
Ej = mean((cD5).^2);

If it make sense, I would also like to know what is the difference between wavelet convolution that you talked in your “zero to hero course” on Udemy and wavedec function in MATLAB. Thanks in advance.

Rab Nawaz

Hi Nawaz. I’m not very familiar with the wavedec function. There are many types of wavelets, and different wavelet families have different characteristics and are optimized for different uses. I think this one might be Daubechies wavelets (I’m guessing from the db5). I use Morlet wavelets because they are smooth and mono-peaked in the frequency domain, and because they allow you specify any peak+width frequency parameters that you like. I guess in your code, each wavelet frequency is exactly 1/2 of the previous wavelet frequency.

If you want to try to replicate their methods exactly, then it’s probably best to contact those authors directly.

Thank you Mike for your quick response.

Yes, you are right, in the code the used Wavelet function is Daubechies and each wavelet frequency is exactly 1/2 of the previous one.

Actually It’s not necessary to replicate their method exactly. I am in the process of addressing one of the reviewer comments for my manuscript. I used time-domain and frequency-domain feature extraction methods in my work and the reviewer asked to include “at least a representative feature extraction method in time-frequency domain (e.g. wavelet transform)”. So, I was trying with Wavelet energy one.

However, any of your suggestions will be appreciated.

Rab Nawaz

Daubechies wavelets are also OK. They have several (smaller) peaks in the frequency domain, though, so they are not as frequency-selective as Morlet wavelets. But from your quote, the reviewer asked for any wavelet transform, not a specific wavelet. So you can also use Morlet wavelets if you like. “Energy” and power are the same thing.

Thank you so much for your suggestion.