Detail about implementation of DWT

107 views
Skip to first unread message

Gautam Sinha

unread,
Mar 11, 2023, 5:25:50 AM3/11/23
to PyWavelets
Hello,

I wanted to ask the about the details regarding the implementation of DWT. I am trying to construct the scalogram for my signal. 

Now when I input a signal of length (1024 = 2^10) and perform a single DWT. The length of approximation and detail coefficients obtained are given by (thanks for stating this explicitly): 
 floor((len(data) + wavelet.dec_len - 1) / 2)

The only mode of extension that gives result is periodization where I get the length to be (len(data)/2). Now I don't want to make an assumption that my data is periodic in nature (because it is not). So, can someone help to explain/give a suggestion about why the extension of length (the length is being extended by (wavelet.dec_len-1/2))? And if I have to plot the scalogram with another type of extension being used, how will I map the coefficients to the length of the original signal?

Yours Sincerely,

Gautam Sinha


Deepu

unread,
May 22, 2023, 1:58:10 AM5/22/23
to PyWavelets
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.

Gautam Sinha

unread,
May 20, 2024, 5:57:46 PM5/20/24
to PyWavelets
To follow up on this answer, I understood the point that the padding is done to prevent the wrap around effect of the boundary coefficients. So, if I have a signal of length N and the filter of size (L-1) then padding will lead to N+L-1 datapoints and then convolution + decimation will lead to (N+L-1)/2 coefficients which matches the number of coefficients given by the formula:   floor((len(data) + wavelet.dec_len - 1) / 2).

The question is where is this implicit padding being done in the software? For example, if I selected zero padding, Is it before the signal so 0,0,0,0,0,a[0],a[1],.....a[N-1] or after the signal  a[0],a[1],a[2],....a[N-1],0,0,0,0... Theoretically, Ruch et al., suggests to do the padding before the signal (helps in preserving orthogonality of the decomposition matrix), but I am not sure as this is used by the algorithm. 

In a grand scheme of things, the idea I wanted to implement was, given a wavelet coefficient at scale j, I wanted to map the datapoints (in the original space) that contributed to this coefficient at scale j. If padding is involved it slightly messes up this mapping, but it can still be implemented if I can account for the location of the padding. 

Any help/ suggestion around this point will be helpful.
Reply all
Reply to author
Forward
0 new messages