Continuous Wave Let Mat Lab
Continuous Wave Let Mat Lab
On this page…
Fourier transform, the analyzing functions are windowed complex exponentials, , and the result in a
function of two variables. The STFT coefficients, represent the match between the signal and a
sinusoid with angular frequency ω in an interval of a specified length centered at τ.
In the CWT, the analyzing function is a wavelet, ψ. The CWT compares the signal to shifted and compressed
or stretched versions of a wavelet. Stretching or compressing a function is collectively referred to as dilation
or scaling and corresponds to the physical notion of scale. By comparing the signal to the wavelet at various
scales and positions, you obtain a function of two variables. The two-dimensional representation of a
one-dimensional signal is redundant. If the wavelet is complex-valued, the CWT is a complex-valued
function of scale and position. If the signal is real-valued, the CWT is a real-valued function of scale and
position. For a scale parameter, a>0, and position, b, the CWT is:
where denotes the complex conjugate. Not only do the values of scale and position affect the CWT
coefficients, the choice of wavelet also affects the values of the coefficients.
By continuously varying the values of the scale parameter, a, and the position parameter, b, you obtain the
cwt coefficients C(a,b). Note that for convenience, the dependence of the CWT coefficients on the function
and analyzing wavelet has been suppressed.
Multiplying each coefficient by the appropriately scaled and shifted wavelet yields the constituent wavelets of
the original signal.
There are many different admissible wavelets that can be used in the CWT. While it may seem confusing that
there are so many choices for the analyzing wavelet, it is actually a strength of wavelet analysis. Depending
on what signal features you are trying to detect, you are free to select a wavelet that facilitates your detection
of that feature. For example, if you are trying to detect abrupt discontinuities in your signal, you may choose
one wavelet. On the other hand, if you are interesting in finding oscillations with smooth onsets and offsets,
you are free to choose a wavelet that more closely matches that behavior.
Back to Top
Scale
Like the concept of frequency, scale is another useful property of signals and images. For example, you can
analyze temperature data for changes on different scales. You can look at year-to-year or decade-to-decade
changes. Of course, you can examine finer (day-to-day), or coarser scale changes as well. Some processes
reveal interesting changes on long time, or spatial scales that are not evident on small time or spatial scales.
The opposite situation also happens. Some of our perceptual abilities exhibit scale invariance. You recognize
people you know regardless of whether you look at a large portrait, or small photograph.
To go beyond colloquial descriptions such as "stretching" or "shrinking" we introduce the scale factor, often
denoted by the letter a. The scale factor is a inherently positive quantity, a>0. For sinusoids, the effect of the
scale factor is very easy to see.
The scale factor works exactly the same with wavelets. The smaller the scale factor, the more "compressed"
the wavelet.
It is clear from the diagrams that, for a sinusoid sin(ωt), the scale factor a is related (inversely) to the radian
frequency ω. This general inverse relationship between scale and frequency holds for signals in general. See
CWT as a Filtering Technique and Scale and Frequency for more information on the relationship between scale
and frequency.
Not only is a time-scale representation a different way to view data, it is a very natural way to view data
derived from a great number of natural phenomena.
Consider a lunar landscape, whose ragged surface (simulated below) is a result of centuries of bombardment
by meteorites whose sizes range from gigantic boulders to dust specks.
If we think of this surface in cross section as a one-dimensional signal, then it is reasonable to think of the
signal as having components of different scales — large features carved by the impacts of large meteorites,
and finer features created by small meteorites.
Here is a case where thinking in terms of scale makes much more sense than thinking in terms of frequency.
Even though this signal is artificial, many natural phenomena — from the intricate branching of blood vessels
and trees, to the jagged surfaces of mountains and fractured metals — lend themselves to an analysis of
scale.
While there is a general relationship between scale and frequency, no precise relationship exists. Users
familiar with Fourier analysis often want to define a mapping between a wavelet at a given scale with a
specified sampling period to a frequency in hertz. You can only do this in a general sense. Therefore, it is
better to talk about the pseudo-frequency corresponding to a scale. The Wavelet Toolbox software provides
two functions centfrq and scal2frq, which enable you to find these approximate scale-frequency
relationships for specified wavelets and scales.
The basic approach identifies the peak power in the Fourier transform of the wavelet as its center frequency
and divides that value by the product of the scale and the sampling interval. See scal2frq for details. The
following example shows the match between the estimated center frequency of the db8 wavelet and a
sinusoid of the same frequency.
The relationship between scale and frequency in the CWT is also explored in CWT as a Filtering Technique.
Back to Top
Shifting
Shifting a wavelet simply means delaying (or advancing) its onset. Mathematically, delaying a function f(t) by
k is represented by f(t – k ):
Back to Top
Back to Top
You can also interpret the CWT as a frequency-based filtering of the signal by rewriting the CWT as an inverse
Fourier transform.
where and are the Fourier transforms of the signal and the wavelet.
From the preceding equations, you can see that stretching a wavelet in time causes its support in the
frequency domain to shrink. In addition to shrinking the frequency support, the center frequency of the
wavelet shifts toward lower frequencies. The following figure demonstrates this effect for a hypothetical
wavelet and scale (dilation) factors of 1,2, and 4.
This depicts the CWT as a bandpass filtering of the input signal. CWT coefficients at lower scales represent
energy in the input signal at higher frequencies, while CWT coefficients at higher scales represent energy in
the input signal at lower frequencies. However, unlike Fourier bandpass filtering, the width of the bandpass
filter in the CWT is inversely proportional to scale. The width of the CWT filters decreases with increasing
scale. This follows from the uncertainty relationships between the time and frequency support of a signal: the
broader the support of a signal in time, the narrower its support in frequency. The converse relationship also
holds.
In the wavelet transform, the scale, or dilation operation is defined to preserve energy. To preserve energy
while shrinking the frequency support requires that the peak energy level increases. The quality factor, or Q
factor of a filter is the ratio of its peak energy to bandwidth. Because shrinking or stretching the frequency
support of a wavelet results in commensurate increases or decreases in its peak energy, wavelets are often
referred to as constant-Q filters.
Back to Top
The time variable in the inverse Fourier transform is the translation parameter, b.
This suggests that you can compute the CWT with the inverse Fourier transform. Because there are efficient
algorithms for the computation of the discrete Fourier transform and its inverse, you can often achieve
considerable savings by using fft and ifft when possible.
To obtain a picture of the CWT in the Fourier domain, start with the definition of the wavelet transform:
If you define:
To obtain the CWT, it appears you have to compute the convolution for each value of the shift parameter, b,
and repeat this process for each scale, a.
However, if the two sequences are circularly-extended (periodized to length N), you can express the circular
convolution as a product of discrete Fourier transforms. The CWT is the inverse Fourier transform of the
product
The cwtft function implements the CWT using an FFT-based algorithm. See cwtftinfo for information
pertaining to the supported analyzing wavelets.
Back to Top
Because the CWT is a redundant transform, there is not a unique way to define the inverse. The inverse CWT
implemented in the Wavelet Toolbox utilizes a discrete version of the single integral formula due to Morlet.
The inverse CWT is classically presented in the double-integral form. Assume you have a wavelet with a
Fourier transform that satisfies the admissibility condition:
The inverse CWT is classically presented in the double-integral form. Assume you have a wavelet with a
Fourier transform that satisfies the admissibility condition:
For wavelets satisfying the admissibility condition and finite-energy functions, f(t), you can define the
inverse CWT as:
For analyzing wavelets and functions satisfying the following conditions, a single integral formula for the
inverse CWT exists. These conditions are:
The analyzed function, f(t), is real-valued and the analyzing wavelet has a real-valued Fourier
transform.
The analyzed function, f(t), is real-valued and the Fourier transform of the analyzing wavelet has
support only on the set of nonnegative frequencies. This is referred to as an analytic wavelet. A
function whose Fourier transform only has support on the set of nonnegative frequencies must be
complex-valued.
The preceding conditions constrain the set of possible analyzing wavelets. If you inspect the list of wavelets
supported by cwtft, each wavelet is either analytic or has a real-valued Fourier transform. Because the
toolbox only supports the analysis of real-valued functions, the real-valued condition on the analyzed
function is always satisfied.
To motivate the single integral formula, let ψ1 and ψ2 be two wavelets that satisfy the following two- wavelet
admissibility condition:
INote that the above constant may be complex-valued. Let f(t) and g(t) be two finite energy functions. If the
two- wavelet admissibility condition is satisfied, the following equality holds:
where < , > denotes the inner product, * denotes the complex conjugate, and the dependence of ψ1 and ψ2
on scale and position has been suppressed for convenience.
The key to the single integral formula for the inverse CWT is to recognize that the two- wavelet admissibility
condition can be satisfied even if one of the wavelets is not admissible. In other words, it is not necessary
that both ψ1 and ψ2 be separately admissible. You can also relax the requirements further by allowing one of
the functions and wavelets to be distributions. By first letting g(t) be the Dirac delta function (a distribution)
and also allowing ψ2 to be the Dirac delta function, you can derive the single integral formula for the inverse
CWT
Back to Top
3. Shift the wavelet to the right and repeat steps 1 and 2 until you've covered the whole signal.
Back to Top
x = zeros(1000,1);
x(500) = 1;
[~,psi,xval] = wavefun('haar',10);
plot(xval,psi); axis([0 1 -1.5 1.5]);
title('Haar Wavelet');
To compute the CWT using the Haar wavelet at scales 1 to 128, enter:
CWTcoeffs = cwt(x,1:128,'haar');
CWTcoeffs is a 128-by-1000 matrix. Each row of the matrix contains the CWT coefficients for one scale.
There are 128 rows because the SCALES input to cwt is 1:128. The column dimension of the matrix matches
the length of the input signal.
Recall that the CWT of a 1D signal is a function of the scale and position parameters. To produce a plot of the
CWT coefficients, plot position along the x-axis, scale along the y-axis, and encode the magnitude, or size
of the CWT coefficients as color at each point in the x-y, or time-scale plane.
You can produce this plot using cwt with the optional input argument 'plot'.
cwt(x,1:128,'haar','plot');
colormap jet; colorbar;
The preceding figure was modified with text labels to explicitly show which colors indicate large and small
CWT coefficients.
You can also plot the size of the CWT coefficients in 3D with
This region is referred to as the cone of influence of the point t=500 for the Haar wavelet. For a given point,
the cone of influence shows you which CWT coefficients are affected by the signal value at that point.
the cone of influence shows you which CWT coefficients are affected by the signal value at that point.
To understand the cone of influence, assume that you have a wavelet supported on [- C, C]. Shifting the
wavelet by b and scaling by a results in a wavelet supported on [- Ca+b, Ca+b]. For the simple case of a
shifted impulse, , the CWT coefficients are only nonzero in an interval around τ equal to the support of
the wavelet at each scale. You can see this by considering the formal expression of the CWT of the shifted
impulse.
For the impulse, the CWT coefficients are equal to the conjugated, time-reversed, and scaled wavelet as a
function of the shift parameter, b. You can see this by plotting the CWT coefficients for a select few scales.
subplot(311)
plot(CWTcoeffs(10,:)); title('Scale 10');
subplot(312)
plot(CWTcoeffs(50,:)); title('Scale 50');
subplot(313)
plot(CWTcoeffs(90,:)); title('Scale 90');
The cone of influence depends on the wavelet. You can find and plot the cone of influence for a specific
wavelet with conofinf.
The next example features the superposition of two shifted impulses, . In this case, use
the Daubechies' extremal phase wavelet with four vanishing moments, db4. The following figure shows the
cone of influence for the points 300 and 500 using the db4 wavelet.
Look at point 400 for scale 20. At that scale, you can see that neither cone of influence overlaps the point
400. Therefore, you can expect that the CWT coefficient will be zero at that point and scale. The signal is only
nonzero at two values, 300 and 500, and neither cone of influence for those values includes the point 400 at
scale 20. You can confirm this by entering:
x = zeros(1000,1);
x([300 500]) = 1;
CWTcoeffs = cwt(x,1:128,'db4');
plot(CWTcoeffs(20,:)); grid on;
Next, look at the point 400 at scale 80. At scale 80, the cones of influence for both points 300 and 500
include the point 400. Even though the signal is zero at point 400, you obtain a nonzero CWT coefficient at
that scale. The CWT coefficient is nonzero because the support of the wavelet has become sufficiently large
at that scale to allow signal values 100 points above and below to affect the CWT coefficient. You can
confirm this by entering:
at that scale to allow signal values 100 points above and below to affect the CWT coefficient. You can
confirm this by entering:
plot(CWTcoeffs(80,:));
grid on;
In the preceding example, the CWT coefficients became large in the vicinity of an abrupt change in the signal.
This ability to detect discontinuities is a strength of the wavelet transform. The preceding example also
demonstrated that the CWT coefficients localize the discontinuity best at small scales. At small scales, the
small support of the wavelet ensures that the singularity only affects a small set of wavelet coefficients.
To demonstrate why the wavelet transform is so adept at detecting abrupt changes in the signal, consider a
shifted Heaviside, or unit step signal.
x = [zeros(500,1); ones(500,1)];
CWTcoeffs = cwt(x,1:64,'haar','plot'); colormap jet;
Similar to the shifted impulse example, the abrupt transition in the shifted step function results in large CWT
coefficients at the discontinuity. The following figure illustrates why this occurs.
In the preceding figure, the red function is the shifted unit step function. The black functions labeled A, B,
and C depict Haar wavelets at the same scale but different positions. You can see that the CWT coefficients
around position A are zero. The signal is zero in that neighborhood and therefore the wavelet transform is
also zero because any wavelet integrates to zero.
Note the Haar wavelet centered around position B. The negative part of the Haar wavelet overlaps with a
region of the step function that is equal to 1. The CWT coefficients are negative because the product of the
Haar wavelet and the unit step is a negative constant. Integrating over that area yields a negative number.
Note the Haar wavelet centered around position C. Here the CWT coefficients are zero. The step function is
equal to one. The product of the wavelet with the step function is equal to the wavelet. Integrating any
wavelet over its support is zero. This is the zero moment property of wavelets.
At position B, the Haar wavelet has already shifted into the nonzero portion of the step function by 1/2 of its
support. As soon as the support of the wavelet intersects with the unity portion of the step function, the CWT
coefficients are nonzero. In fact, the situation illustrated in the previous figure coincides with the CWT
coefficients achieving their largest absolute value. This is because the entire negative deflection of the
wavelet oscillation overlaps with the unity portion of the unit step while none of the positive deflection of the
wavelet does. Once the wavelet shifts to the point that the positive deflection overlaps with the unit step,
there will be some positive contribution to the integral. The wavelet coefficients are still negative (the
negative portion of the integral is larger in area), but they are smaller in absolute value than those obtained at
position B.
The following figure illustrates two other positions where the wavelet intersects the unity portion of the unit
step.
In the top figure, the wavelet has just begun to overlap with the unity portion of the unit step. In this case,
the CWT coefficients are negative, but not as large in absolute value as those obtained at position B. In the
bottom figure, the wavelet has shifted past position B and the positive deflection of the wavelet begins to
contribute to the integral. The CWT coefficients are still negative, but not as large in absolute value as those
obtained at position B.
You can now visualize how the wavelet transform is able to detect discontinuities. You can also visualize in
this simple example exactly why the CWT coefficients are negative in the CWT of the shifted unit step using
the Haar wavelet. Note that this behavior differs for other wavelets.
x = [zeros(500,1); ones(500,1)];
CWTcoeffs = cwt(x,1:64,'haar','plot'); colormap jet;
% plot a few scales for visualization
subplot(311);
plot(CWTcoeffs(5,:)); title('Scale 5');
subplot(312);
plot(CWTcoeffs(10,:)); title('Scale 10');
subplot(313);
plot(CWTcoeffs(50,:)); title('Scale 50');
Next consider how the CWT represents smooth signals. Because sinusoidal oscillations are a common
phenomenon, this section examines how sinusoidal oscillations in the signal affect the CWT coefficients. To
begin, consider the sym4 wavelet at a specific scale superimposed on a sine wave.
Recall that the CWT coefficients are obtained by computing the product of the signal with the shifted and
scaled analyzing wavelet and integrating the result. The following figure shows the product of the wavelet
and the sinusoid from the preceding figure.
You can see that integrating over this product produces a positive CWT coefficient. That results because the
oscillation in the wavelet approximately matches a period of the sine wave. The wavelet is in phase with the
sine wave. The negative deflections of the wavelet approximately match the negative deflections of the sine
wave. The same is true of the positive deflections of both the wavelet and sinusoid.
The following figure shifts the wavelet 1/2 of the period of the sine wave.
Examine the product of the shifted wavelet and the sinusoid.
You can see that integrating over this product produces a negative CWT coefficient. That results because the
wavelet is 1/2 cycle out of phase with the sine wave. The negative deflections of the wavelet approximately
match the positive deflections of the sine wave. The positive deflections of the wavelet approximately match
the negative deflections of the sinusoid.
Finally, shift the wavelet approximately one quarter cycle of the sine wave.
The following figure shows the product of the shifted wavelet and the sinusoid.
Integrating over this product produces a CWT coefficient much smaller in absolute value than either of the
two previous examples. That results because the negative deflection of the wavelet approximately aligns with
a positive deflection of the sine wave. Also, the main positive deflection of the wavelet approximately aligns
with a positive deflection of the sine wave. The resulting product looks much more like a wavelet than the
other two products. If it looked exactly like a wavelet, the integral would be zero.
At scales where the oscillation in the wavelet occurs on either a much larger or smaller scale than the period
of the sine wave, you obtain CWT coefficients near zero. The following figure illustrates the case where the
wavelet oscillates on a much smaller scale than the sinusoid.
The product shown in the bottom pane closely resembles the analyzing wavelet. Integrating this product
results in a CWT coefficient near zero.
The following example constructs a 60-Hz sine wave and obtains the CWT using the sym8 wavelet.
t = linspace(0,1,1000);
x = cos(2*pi*60*t);
CWTcoeffs = cwt(x,1:64,'sym8','plot'); colormap jet;
Note that the CWT coefficients are large in absolute value around scales 9 to 21. You can find the
pseudo-frequencies corresponding to these scales using the command:
freq = scal2frq(9:21,'sym8',1/1000);
Note that the CWT coefficients are large at scales near the frequency of the sine wave. You can clearly see the
sinusoidal pattern in the CWT coefficients at these scales with the following code.
Note that the CWT coefficients are large at scales near the frequency of the sine wave. You can clearly see the
sinusoidal pattern in the CWT coefficients at these scales with the following code.
The final example constructs a signal consisting of both abrupt transitions and smooth oscillations. The
signal is a 4-Hz sinusoid with two introduced discontinuities.
N = 1024;
t = linspace(0,1,1024);
x = 4*sin(4*pi*t);
x = x - sign(t - .3) - sign(.72 - t);
plot(t,x); xlabel('t'); ylabel('x');
grid on;
CWTcoeffs = cwt(x,1:180,'sym4');
imagesc(t,1:180,abs(CWTcoeffs));
colormap jet; axis xy;
xlabel('t'); ylabel('Scales');
Note that the CWT detects both the abrupt transitions and oscillations in the signal. The abrupt transitions
affect the CWT coefficients at all scales and clearly separate themselves from smoother signal features at
small scales. On the other hand, the maxima and minima of the 2–Hz sinusoid are evident in the CWT
coefficients at large scales and not apparent at small scales.
The following general principles are important to keep in mind when interpreting CWT coefficients.
Cone of influence— Depending on the scale, the CWT coefficient at a point can be affected by signal
values at points far removed. You have to take into account the support of the wavelet at specific
scales. Use conofinf to determine the cone of influence. Not all wavelets are equal in their support.
For example, the Haar wavelet has smaller support at all scales than the sym4 wavelet.
Detecting abrupt transitions— Wavelets are very useful for detecting abrupt changes in a signal.
Abrupt changes in a signal produce relatively large wavelet coefficients (in absolute value) centered
around the discontinuity at all scales. Because of the support of the wavelet, the set of CWT
coefficients affected by the singularity increases with increasing scale. Recall this is the definition of
the cone of influence. The most precise localization of the discontinuity based on the CWT coefficients
is obtained at the smallest scales.
Detecting smooth signal features— Smooth signal features produce relatively large wavelet
coefficients at scales where the oscillation in the wavelet correlates best with the signal feature. For
sinusoidal oscillations, the CWT coefficients display an oscillatory pattern at scales where the
oscillation in the wavelet approximates the period of the sine wave.
Back to Top
Back to Top
Was this topic helpful? Yes No