The length extension in wavelet decomposition arises from the nature of the discrete wavelet transform (DWT) and the need to apply the wavelet filter banks to the signal. The extension allows the DWT to preserve the same signal length while incorporating the boundary effects caused by the filtering process.
When performing a single-level DWT on a signal of length N, the length of the approximation and detail coefficients depends on the specific wavelet being used and the extension mode applied. The formula you provided, `floor((len(data) + wavelet.dec_len - 1) / 2)`, calculates the length of the approximation coefficients.
In the case of periodization extension, which is often used as the default extension mode in DWT, the length of the approximation coefficients is `len(data)/2`. This is because periodization extension duplicates the signal by wrapping it around its endpoints, effectively doubling its length. The duplicated signal is then passed through the wavelet filter banks, and the resulting approximation coefficients are downsampled to half the length of the original signal.
If you want to use a different extension mode for the DWT, such as zero-padding, symmetric, or smooth extension, you need to handle the boundary effects and adjust the length of the coefficients accordingly.
To map the coefficients to the length of the original signal when using a different extension mode, you can consider the following steps:
1. Apply the desired extension mode to the signal, resulting in an extended signal.
2. Perform the DWT using the extended signal.
3. Retrieve the approximation coefficients, which will have a different length than the original signal due to the extension.
4. If necessary, truncate or pad the approximation coefficients to match the length of the original signal.
By mapping the coefficients to the original signal length, you can accurately visualize the scalogram or analyze the wavelet coefficients without introducing artificial effects caused by the extension.
Keep in mind that different extension modes have different characteristics and may be more suitable for specific types of signals or applications. It's important to consider the properties of your signal and the requirements of your analysis when choosing the extension mode for the DWT.