# Understanding Wavelets, Part 4: An Example application of Continuous Wavelet Transform

From the series: Understanding Wavelets

In this video, we will see a practical application of the wavelet concepts we learned earlier. I will illustrate how to obtain a good time-frequency analysis of a signal using the Continuous Wavelet Transform. To begin, let us load an earthquake signal in MATLAB. This signal is sampled at 1 Hz for a duration of 51 minutes. You can view the signal using the plot command. Looking at the time domain representation of the signal, we see two distinct regions.  The first seismic activity occurs around the 30 minute mark. This lasts for a very short duration. The second seismic activity occurs sometime around 34 minutes and is relatively longer. You can see how it is difficult to separate the noise from the seismic signals just by looking at the time-domain representation. Many naturally occurring signals have similar characteristics. They are composed of slowly varying components interspersed with abrupt changes and are often buried in noise. Wavelets are very useful in analyzing these kinds of signals. We will see how a bit later. But first, let us see what happens when we use the short time Fourier transform to produce a time-frequency visualization. We pass in the signal and the sampling frequency as input arguments to the function spectrogram. Looking at the output, you can see that the two instances of seismic activity we just saw are now indistinguishable. All we see is a signal whose frequency is spread around 0.05 Hz but is not very well localized. Let us see what happens when we try to localize the events by reducing the window size used in the spectrogram. By reducing the size of the window, we see some bright spots around 30 and 33 mins, but the two events are not well separated. The frequency and time uncertainty of the events is still very high. Reducing the window size was not very helpful. We need to somehow localize the frequency information of these two events. Now let us repeat the analysis - this time using wavelets. We will use the CWT function in MATLAB to compute the Continuous Wavelet Transform. This will help obtain a joint time frequency analysis of the earthquake data. The CWT function supports these analytic key wavelets. If you don’t specify which wavelet you want to use, the CWT uses morse wavelets by default. When no output parameters are specified, the function, CWT produces a joint time -frequency visualization of the input signal. The minimum and maximum scales for analysis are determined automatically by the CWT function based on the wavelet's energy spread. The magnitude of the wavelet coefficients returned by the function are color coded. The white dashed lines denote the cone of influence. Within this region, the wavelet coefficient estimates are reliable. Looking at the plot, we can see the two regions produced by the earthquake. The first seismic activity is clearly separated from the second. Both these events seem to be well localized in time and frequency. For a richer time-frequency analysis, you can choose to vary the wavelet scales over which you want to carry out the analysis. You can do this by using different parameters. For this example, we will set the number of octaves to 10 and the number of voices per octave to 32. The function returns the wavelet coefficients and the equivalent frequencies as outputs. We can plot the coefficients a as function of time and frequency plot, using the surface command. Looking at this plot, it is clear that the frequency of the seismic event ranges from 0.03 Hz to 0.06 Hz. We can also reconstruct the time-domain representation of this seismic event from the wavelet coefficients using the function icwt. We pass in the wavelet coefficients and the frequency vector, which is the output of the CWT function. We also pass the frequency range of the signal that we want to extract. In this case, we’re inputting  0.03 to 0.06. The output is a time-domain representation of the seismic signal of interest. This way, you can use wavelets for performing joint time-frequency analysis.