Calculating the Continuous 1-D Wavelet Transform with the new Function cwt, Part 1

In MATLAB R2016b, the function to calculate a continuous 1D wavelet transform has been replaced by a new function, unfortunately with the same name. Here is a great example why I think that this blog is very useful: Here I can let you know how I would modify the script of Chapter 5.8 of MRES and ask for your comments on it, long before the 5th edition of MRES will be published.

I use the same synthetic data stored in the file series3.txt as an example. As before, you first have to interpolate your data to an evenly spaced time vector t, using the minimum and maximum values of your original time axes and a sampling interval close to the mean sampling interval of your data, which is 3.0030 in my synthetic example.

If your time series has a trend please detrend it before running the Wavelet analysis:

series3L = detrend(series3L);

Then you usecwt with the data seriesseries3L and the inverse of your sampling interval. In our example, the sampling interval is 3, therefore the sampling frequency is 1/3. The output is the wavelet transformwt, the frequenciesf and the cone of influencecoi to mark the area were edge effects occur in the CWT. This is the newcwt function introduced with MATLAB R2016b. It uses an FFT-based algorithm, similar to the one introduced by Torrence and Compo (Here is a link to their classic Wavelet webpage, also cited in my textbook) and which was already used by the old functioncwtft which is no longer supported, similar to the old version ofcwt. The advantage of the new cwt function provides defaults, different from the old version, allowing to run a wavelet analysis without caring too much about the settings. Here is some background information about the case by The MathWorks Inc. about the change.

[wt,f,coi] = cwt(series3L,1/3);

Now we display the wavelet power spectrum. You can change the limits of the axes, the colormap and many other things. I did not yet successfully plot the cone of influence here. You can see cycles with frequencies of 0.01/kyr (corresponding to a period of 100 kyr), 0.025 (40 kyr) and 0.05 (20 kyr). The great thing about Wavelets is that it displays an evolutionary spectrum, i.e. the appearance and disappearance of cycles through time.

Alternatively, we can use the graphical output of the functioncwt. It is a bit tricky to change the display of the graphics. Unfortunately changing the axes limits is tricky because the axes are independent from the colorful display of the wavelet transform. Browsing the code of cwt reveals that it actually uses imagesc to create the pseudocolor plot and then create an independent axis system on top of that. I will keep trying, the numbers on the y-axis really look bad. Typingdoc ctw in the Command Window shows that the developers obviously do not care about the tick labels.

Do you like the new cwt function? Here is the a zipped archive of the MATLAB live script, the classic script and the PDF version of the live script, together with the synthetic data file. Commands via email are, as always, very welcome. Please note that there is an update of this post.

About me

I am a geoscientist, apl. professor of paleoclimate dynamics at the University of Potsdam. I have been using MATLAB since late 1992, especially for the analysis of paleoclimatic series. Please visit my university webpage http://martinhtrauth.de