# MATLAB Codes for Wavelet Packet Transform¶

MATLAB folder in the GitHub repository includes four codes.

WP_Energy_Ratio: Computes the energy ratios of the wavelet packets for specified level of transform for chosen time series. It returns plots which contains energy ratios of each packet for time series, reconstructed time series and their FFT plot. User can define the informative wavelet packet number using these plot.WP_Informative_Packet_Recon: For selected level of WPT, it reconstructs time series based on chosen informative wavelet packets. It saves the reconstructed time series into specified folder.WP_Frequency_Domain_Features: Computes the frequency domain features for selected level of Transform by using reconstructed time series withWP_Informative_Packet_Reconfunction. It saves the feature matrix and this feature matrix will be combined with time domain features to be used in classification.Example_Usage: Provides examples for MATLAB codes.

**NOTE**: For more details on these functions, please see the function descriptions in MATLAB files.

## Wavelet packet numbering in MATLAB¶

The numbering of the wavelet packets obtained after applying WPT can confuse user. Therefore, we give proper instructions here how to obtain and track the wavelet packets correctly. There are two types of ordering of the wavelet packets and these are natural ordering and frequency ordering. We show these two types of ordering in Wavelet packet tree in Fig. 1.

The ordering is given in natural ordering in MATLAB. However, we use frequency ordering in this toolbox. In addition, MATLAB does not reset the numbering of wavelet packets to 1 in each level of transform.
For example, if the first level wavelet packets are called first and second wavelet packets, first packet of the second level transform is called third wavelet packet.
Please see Fig. 2 for MATLAB numbering.
The frequency ordering given in Fig. 1 is resetting the numbers to 1 in each level.
All wavelet packet numbers given in [Yesilli2019] is based on the ordering provided in Fig. 1.
One need to find correponding number for each wavelet packet by using Fig. 2 to reconstruct the time series correctly based on informative wavelet packets in MATLAB.
Also, ordering in Fig. 1 is obtained by using the MATLAB function **otnodes()**.
Ordering can differ based on wavelet function used in the transform and level of the transform.
Therefore, ordering in Fig. 1 should only be used in applications which use wavelet function ‘db10’.