Wavelet Matlab

0 views
Skip to first unread message

Alexandrie Gallup

unread,
Aug 5, 2024, 8:48:11 AM8/5/24
to downnessiefrer
Wavelettransforms are mathematical tools for analyzing data where features vary over different scales. For signals, features can be frequencies varying over time, transients, or slowly varying trends. For images, features include edges and textures. Wavelet transforms were primarily created to address limitations of the Fourier transform.

Audio signals, time-series financial data, and biomedical signals typically exhibit piecewise smooth behavior punctuated by transients. Similarly, images typically include homogenous, piecewise smooth regions separated by transients, which appear as edges. For both signals and images, the smooth regions and transients can be sparsely represented with wavelet transforms.


The continuous wavelet transform is a time-frequency transform, which is ideal for analysis of non-stationary signals. A signal being nonstationary means that its frequency-domain representation changes over time. CWT is similar to the short-time Fourier transform (STFT). The STFT uses a fixed window to create a local frequency analysis, while CWT tiles the time-frequency plane with variable-sized windows. The window widens in time, making it suitable for low-frequency phenomena, and narrows for high-frequency phenomena. The continuous wavelet transform can be used to analyze transient behavior, rapidly changing frequencies, and slowly varying behavior.


Analyzing a hyperbolic chirp signal (left) with two components that vary over time in MATLAB. The short-time Fourier transform (center) does not clearly distinguish the instantaneous frequencies, but the continuous wavelet transform (right) accurately captures them. See the MATLAB code.


With the discrete wavelet transform scales are discretized more coarsely than with CWT. This makes DWT useful for compressing and denoising signals and images while preserving important features. You can use discrete wavelet transforms to perform multiresolution analysis and split signals into physically meaningful and interpretable components.


This introductory video covers what wavelets are and how you can use them to explore your data in MATLAB. The video focuses on two important wavelet transform concepts: scaling and shifting. The concepts can be applied to 2D data such as images.




Hello, everyone. In this introductory session, I will cover some basic wavelet concepts. I will be primarily using a 1-D example, but the same concepts can be applied to images, as well. First, let's review what a wavelet is. Real world data or signals frequently exhibit slowly changing trends or oscillations punctuated with transients. On the other hand, images have smooth regions interrupted by edges or abrupt changes in contrast. These abrupt changes are often the most iA=nteresting parts of the data, both perceptually and in terms of the information they provide. The Fourier transform is a powerful tool for data analysis. However, it does not represent abrupt changes efficiently. The reason for this is that the Fourier transform represents data as sum of sine waves, which are not localized in time or space. These sine waves oscillate forever. Therefore, to accurately analyze signals and images that have abrupt changes, we need to use a new class of functions that are well localized in time and frequency: This brings us to the topic of Wavelets. A wavelet is a rapidly decaying, wave-like oscillation that has zero mean. Unlike sinusoids, which extend to infinity, a wavelet exists for a finite duration. Wavelets come in different sizes and shapes. Here are some of the well-known ones. The availability of a wide range of wavelets is a key strength of wavelet analysis. To choose the right wavelet, you'll need to consider the application you'll use it for. We will discuss this in more detail in a subsequent session. For now, let's focus on two important wavelet transform concepts: scaling and shifting. Let' start with scaling. Say you have a signal PSI(t). Scaling refers to the process of stretching or shrinking the signal in time, which can be expressed using this equation [on screen]. S is the scaling factor, which is a positive value and corresponds to how much a signal is scaled in time. The scale factor is inversely proportional to frequency. For example, scaling a sine wave by 2 results in reducing its original frequency by half or by an octave. For a wavelet, there is a reciprocal relationship between scale and frequency with a constant of proportionality. This constant of proportionality is called the "center frequency" of the wavelet. This is because, unlike the sinewave, the wavelet has a band pass characteristic in the frequency domain. Mathematically, the equivalent frequency is defined using this equation [on screen], where Cf is center frequency of the wavelet, s is the wavelet scale, and delta t is the sampling interval. Therefore when you scale a wavelet by a factor of 2, it results in reducing the equivalent frequency by an octave. For instance, here is how a sym4 wavelet with center frequency 0.71 Hz corresponds to a sine wave of same frequency. A larger scale factor results in a stretched wavelet, which corresponds to a lower frequency. A smaller scale factor results in a shrunken wavelet, which corresponds to a high frequency. A stretched wavelet helps in capturing the slowly varying changes in a signal while a compressed wavelet helps in capturing abrupt changes. You can construct different scales that inversely correspond the equivalent frequencies, as mentioned earlier. Next, we'll discuss shifting. Shifting a wavelet simply means delaying or advancing the onset of the wavelet along the length of the signal. A shifted wavelet represented using this notation [on screen] means that the wavelet is shifted and centered at k. We need to shift the wavelet to align with the feature we are looking for in a signal.The two major transforms in wavelet analysis are Continuous and Discrete Wavelet Transforms. These transforms differ based on how the wavelets are scaled and shifted. More on this in the next session. But for now, you've got the basic concepts behind wavelets.


wt = cwt(x) returns the continuous wavelet transform (CWT) of x. The CWT is obtained using the analytic Morse wavelet with the symmetry parameter, gamma (γ), equal to 3 and the time-bandwidth product equal to 60. cwt uses 10 voices per octave. The minimum and maximum scales are determined automatically based on the energy spread of the wavelet in frequency and time.


The cwt function uses L1 normalization. With L1 normalization, if you have equal amplitude oscillatory components in your data at different scales, they will have equal magnitude in the CWT. Using L1 normalization shows a more accurate representation of the signal. See L1 Norm for CWT and Continuous Wavelet Transform of Two Complex Exponentials.


[wt,f] =cwt(___,fs) specifies the sampling frequency, fs, in hertz, and returns the scale-to-frequency conversions f in hertz. If you do not specify a sampling frequency, cwt returns f in cycles per sample.


[wt,period]= cwt(___,ts) specifies the sampling period, ts, as a positive duration scalar. cwt uses ts to compute the scale-to-period conversions, period. period is an array of durations with the same Format property as ts.


cwt(___) with no output arguments plots the CWT scalogram. The scalogram is the absolute value of the CWT plotted as a function of time and frequency. Frequency is plotted on a logarithmic scale. The cone of influence showing where edge effects become significant is also plotted. Gray regions outside the dashed white line delineate regions where edge effects are significant. If the input signal is complex-valued, the positive (counterclockwise) and negative (clockwise) components are plotted in separate scalograms.


If you do not specify a sampling frequency or sampling period, the frequencies are plotted in cycles per sample. If you specify a sampling frequency, the frequencies are in hertz. If you specify a sampling period, the scalogram is plotted as a function of time and periods. If the input signal is a timetable, the scalogram is plotted as a function of time and frequency in hertz and uses the RowTimes as the basis for the time axis.


Note the magnitudes of the complex exponential components in the colorbar are essentially their amplitudes even though they are at different scales. This is a direct result of the L1 normalization. You can verify this by executing this script and exploring each subplot with a data cursor.


Create a signal composed of two sinusoids with disjoint support in time. One sinusoid has a frequency of 32 Hz and amplitude equal to 1. The other sinusoid has a frequency of 64 Hz and amplitude equal to 2. The signal is sampled for one second at 1000 Hz. Plot the signal.


Create a CWT filter bank that can be applied to the signal. Since the signal component frequencies are known, set the frequency limits of the filter bank to a narrow range that includes the known frequencies. To confirm the range, plot the magnitude frequency responses for the filter bank.


Use a data cursor to confirm that the amplitudes of the wavelet coefficients are essentially equal to the amplitudes of the sinusoidal components. Your results should be similar to the ones in the following figure.


The -report flag is optional. Using -report generates a code generation report. In the Summary tab of the report, you can find a GPU code metrics link, which provides detailed information such as the number of CUDA kernels generated and how much memory was allocated.


Create two sine waves with frequencies of 32 and 64 Hz. The data is sampled at 1000 Hz. The two sine waves have disjoint support in time. Add white Gaussian noise with a standard deviation of 0.05. Obtain and plot the CWT using the default Morse wavelet.


The plot uses a logarithmic frequency axis because frequencies in the CWT are logarithmic. In MATLAB, logarithmic axes are in powers of 10 (decades). You can use cwtfreqbounds to determine what the minimum and maximum wavelet bandpass frequencies are for a given signal length, sampling frequency, and wavelet.

3a8082e126
Reply all
Reply to author
Forward
0 new messages