# Any experiences for plotting a stationary wavelet transform?

I am experimenting with wavelets for my thesis and am currently working with the stationary WT pywavelets provides. There are very nice plots for CWTs, but does anyone know a technique for producing a plot that gives a good overall understanding of the produced SWT? Right now I am basically just producing a list of details coefficient plots for each level, and not regarding the averages at all.

I hope this question belongs here. Cheers!

EDIT:

I really just iterate through the transform and plot each details coefficient vector. (I'm aware the example uses DWT and not SWT, but it should be analogous)

fig, axes = plt.subplots(3, 5, figsize=[14, 8])

c = pywt.wavedec(data1, 'haar', mode='periodization')

for i in range(0, 5): axes[0, i].plot(c[i],c = "r")

The result then looks like this:

• SWT is easier than DWT in the sense that you can provides plots (2D) similar to that of the CWT. Could you show what you do plot? – Laurent Duval Aug 6 '19 at 14:19
• Thanks. I added the plots I got. – wavelet_guest Aug 6 '19 at 15:04

I don't do Python, I'm an old person sticking to his old Matlab (codes and) habits. However, up to extension/wavelet/border issues, SWT is a discrete equivalent to CWT. And in most versions, the number of samples in approximations or details is the same (which is not the case for the DWT). Hence, you can concatenate 1D rows of details (or approximations) into 2D images, akin to traditional scalograms. The following images and code show the process. I have generated a random piecewise polynomial signal with increasing degrees. Then rows of details, and an image of the rows concatenated. The motivation is to address the impact of vanishing moments on piece-wise polynomials, with border effects. Here are two different realizations.

The Matlab code, that may be reproduced in Python:

dataLength = 512;
data = zeros(dataLength,1);
nChunk = 4;
lChunk = dataLength/nChunk;
for iChunk = 0:nChunk-1
idxChunk = iChunk*lChunk+(1:lChunk)';
polyChunk = rand(iChunk+1,1)-0.5;
dataChunk = polyval(polyChunk,linspace(-0.5,0.5,lChunk));
data(idxChunk) = dataChunk;
end

nLevel = 4;
[swa,swd] = swt(data,nLevel,'db2');

figure(1);clf
subplot(1,3,1)
plot(data,'x');axis tight
for iPlot = 1:nLevel
subplot(nLevel,3,3*(iPlot-1)+2)
plot(swd(iPlot,:));;axis tight
end
subplot(1,3,3)
imagesc(swd)


• Thanks a lot, I will try it out in Matlab, and see how I can convert it to python. Do you think that, if I were to plot a DWT, that I could use the method you propose by duplicating the coefficients in each level? Or are there other methods for that? (Or should I make a separate question for this?) – wavelet_guest Aug 7 '19 at 17:40
• Duplicating at each level is a traditional way to plot scalograms for the DWT. It is not fully accurate though, but helps the visualization. No need to duplicate the question, as long as you upvote :) But I have plots ready in the second option. Note that DWT are irregular samplings of CWT... quite interesting – Laurent Duval Aug 7 '19 at 18:10
• Allright, I understand the Matlab example now. Thanks again. Since I will be looking for patterns in the wavelet transform, I thought I should use the SWT, since apparently SWT is better for that sort of analysis, but I will try out both for now, I think. In your example, the detail coefficients have not been altered, right? Wouldn't I want to scale them somehow, so that coefficients of different levels become comparable? I find it fascinating that DWT does so much decimating, and the inverse transform can still work. (I did upvote, but it says my reputation is too low to show it :-/ ) – wavelet_guest Aug 8 '19 at 13:04
• Thank you, and be patient for the reputation. DWT is sheer magic: perserving invertibility by combining two aliased filters... The prices to pay are a limited choice of wavelets, and shift-variance. SWT is shift-invariant, hence probably easier to use and handle for patterns. You can turn to DWT later if you need optimized computations – Laurent Duval Aug 8 '19 at 13:13
• I will definitely explore SWT deeper. I'm a bit scared that the zeroes the method introduces might skew the results. But that's possibly only because I don't understand SWT well enough yet. Would you recommend scaling the detail coefficients, so that coefficients of different levels become comparable? – wavelet_guest Aug 8 '19 at 13:43