Selected Reading

SciPy - Wavelet Transform



Wavelet Transforms in SciPy

In SciPy the Wavelet Transform refers to a mathematical technique provided by the scipy.signal module that allows the decomposition of a signal into different frequency components using wavelets. It provides tools to analyze signals at multiple scales by making it particularly useful for non-stationary signals where frequency content changes over time.

The Key definition of Wavelet Transform in SciPy can be given as Wavelet Transform applies scaled and shifted versions of a chosen wavelet function to the input signal to analyze its frequency and temporal characteristics simultaneously.

Wavelet Transform can be broadly categorized based on how the signal is analyzed and the nature of the wavelet functions used. They are as follows −

Continuous Wavelet Transform (CWT)

The Continuous Wavelet Transform (CWT) provides a continuous time-frequency representation of a signal by scaling and translating a wavelet function continuously.

Key Features

Following are the key features of the Continuous Wavelet Transform(CWT) −

  • High resolution but computationally expensive.
  • Redundant representation of data.
  • Useful for analyzing non-stationary signals.

Applications: Biomedical signal analysis, seismic data, speech processing.

Discrete Wavelet Transform (DWT)

The Discrete Wavelet Transform (DWT) Decomposes a signal into approximation and detail coefficients at discrete scales using filter banks.

Key Features

Here are the key features of the Discrete Wavelet Transform(DWT) −

  • Efficient, non-redundant multi-resolution analysis.
  • Downsampling reduces data size at each level.
  • It is used in compression and denoising.

Applications: Image compression (JPEG2000), feature extraction, signal processing.

Stationary Wavelet Transform (SWT)

The Stationary Wavelet Transform (SWT) is a modification of DWT that avoids downsampling by preserving the signal length at each decomposition level.

Key Features

Below are the key features of the Stationary Wavelet Transform(SWT) −

  • Efficient, non-redundant multi-resolution analysis.
  • Downsampling reduces data size at each level.
  • It is used in compression and denoising.

Applications: Biomedical signal denoising, image texture analysis.

Wavelet Packet Transform (WPT)

The Wavelet Packet Transform (WPT) is the extended DWT by recursively decomposing both approximation and detail coefficients, offering a full binary tree representation.

Key Features

Following are the key features of the Wavelet Packet Transform (WPT) −

  • Provides finer frequency resolution.
  • Computationally intensive but useful for detailed analysis.
  • Useful in high-precision applications.

Applications: Speech and vibration analysis, pattern recognition.

Multi-Resolution Analysis (MRA)

Multi-Resolution Analysis (MRA) is a framework in wavelet analysis that represents signals at different resolutions by iterative decomposition.

Key Features

Below are the key features of the Multi-Resolution Analysis (MRA) −

  • Hierarchical representation of signals.
  • Provides insight into features at different scales.
  • Often used with DWT.

Applications: Data compression, image processing.

Example

Here is the basic example shows how the DWT breaks a signal down into different frequency components which can be useful for many applications such as signal compression and noise removal.

import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import convolve

# Generate a sample signal: a sum of two sine waves with different frequencies
t = np.linspace(0, 1, 1000, endpoint=False)
signal = np.sin(2 * np.pi * 50 * t) + np.sin(2 * np.pi * 120 * t)

# Manually create a Morlet wavelet
def morlet_wavelet(t, w=5):
    return np.exp(2j * np.pi * t) * np.exp(-t**2 / (2 * w**2))

# Create Morlet wavelet (using real part only)
wavelet = np.real(morlet_wavelet(t, w=5))

# Convolve the signal with the Morlet wavelet to perform a simple wavelet-based transform
convolved_signal = convolve(signal, wavelet, mode='same')

# Plot original signal and convolved signal
plt.figure(figsize=(12, 6))

# Plot the original signal
plt.subplot(2, 1, 1)
plt.plot(t, signal)
plt.title("Original Signal: Sum of Sine Waves")
plt.xlabel("Time [s]")
plt.ylabel("Amplitude")

# Plot the convolved (wavelet-transformed) signal
plt.subplot(2, 1, 2)
plt.plot(t, convolved_signal)
plt.title("Signal After Convolution with Morlet Wavelet")
plt.xlabel("Time [s]")
plt.ylabel("Amplitude")

plt.tight_layout()
plt.show()

Following is the output of the basic example of Morlet Wavelet Transform −

Morlet Wavelet Output

Here are the functions available in SciPy which are used to perform different Wavelet Transform −

S.No. Function & Description
1 scipy.signal.correlate()
Cross-correlation measures the similarity between two signals as a function of the time-lag applied to one of them.
2 scipy.signal.convolve()
Convolution is used to apply a filter to a signal.

Applications of Wavelet Transform

Here are the applications of the Wavelet Transform −

  • Signal Denoising: Suppressing noise while retaining significant features.
  • Compression: Reducing data storage by preserving only important coefficients.
  • Feature Extraction: Used in machine learning and biomedical applications.
  • Time-Frequency Analysis: Identifying transient events in signals.
  • Image Processing: Edge detection and compression.
Advertisements