SciPy - Multi-Resolution Analysis (MRA)



Multi-Resolution Analysis in SciPy

The Multi-Resolution Analysis (MRA) is a fundamental concept in wavelet analysis that enables the decomposition of signals into different resolution levels. It provides a systematic way to analyze signals at multiple scales by capturing both coarse and fine details. MRA is widely used in signal processing applications such as denoising, compression and feature extraction.

The Multi-Resolution Analysis is based on the scaling function (t) and the wavelet function (t) which are used to represent a signal f(t) at different resolution levels. Mathematically, MRA is defined as follows −

f(t) = ∑jk cj, k φ(t - k 2j) + ∑jk dj, k ψ(t - k 2j)

Where −

  • f(t) is the original signal.
  • (t) is the scaling function that represents the approximation at each level.
  • (t) is the wavelet function that captures the detail components.
  • cj,k are the approximation coefficients.
  • dj,k are the detail coefficients.

Key Properties of Multi-Resolution Analysis

The Multi-Resolution Analysis provides the following key properties in SciPy −

  • Hierarchical Signal Representation: MRA decomposes a signal into different levels of approximation and detail components.
  • Localization: MRA provides time-frequency localization by making it useful for analyzing transient and non-stationary signals.
  • Data Reduction: MRA reduces the amount of data needed to represent a signal by focusing on relevant features at each resolution.
  • Smooth and Detail Separation: MRA separates the low-frequency (approximation) and high-frequency (detail) components effectively.

Multi-Resolution Decomposition of a signal

Multi-Resolution Decomposition (MRD) using PyWavelets allows breaking down a signal into different resolution levels by applying Discrete Wavelet Transform (DWT). This helps analyze both coarse and fine details of the signal efficiently. MRD is widely used in applications such as signal compression, feature extraction and denoising.

In PyWavelets, the wavedec() function is used to perform multi-level decomposition of a signal. It returns the approximation and detail coefficients at each decomposition level.

Following is the example which shows how to decompose a signal into multiple levels using PyWavelets −

import numpy as np
import pywt
import matplotlib.pyplot as plt

# Generate a sample signal (a combination of sine waves)
t = np.linspace(0, 1, 500, endpoint=False)  # Time vector
signal = np.sin(2 * np.pi * 5 * t) + np.sin(2 * np.pi * 20 * t)  # Combination of frequencies

# Perform Multi-Level DWT decomposition using Daubechies wavelet ('db4')
coeffs = pywt.wavedec(signal, 'db4', level=3)

# Extract approximation and detail coefficients
cA3, cD3, cD2, cD1 = coeffs  # cA3: Approximation at level 3, cD3: Detail at level 3, etc.

# Plot the original signal and decomposition results
plt.figure(figsize=(10, 10))

# Plot the original signal
plt.subplot(5, 1, 1)
plt.plot(t, signal)
plt.title("Original Signal")
plt.xlabel("Time")
plt.ylabel("Amplitude")

# Plot approximation coefficients at level 3
plt.subplot(5, 1, 2)
plt.plot(cA3)
plt.title("Approximation Coefficients at Level 3")

# Plot detail coefficients at level 3
plt.subplot(5, 1, 3)
plt.plot(cD3)
plt.title("Detail Coefficients at Level 3")

# Plot detail coefficients at level 2
plt.subplot(5, 1, 4)
plt.plot(cD2)
plt.title("Detail Coefficients at Level 2")

# Plot detail coefficients at level 1
plt.subplot(5, 1, 5)
plt.plot(cD1)
plt.title("Detail Coefficients at Level 1")

plt.tight_layout()
plt.show()

Below is the output of the Multi-Level Wavelet Decomposition −

Multi-Resolution Decomposition

Multi-Resolution Decomposition of multiple signals

This example shows how multi-resolution decomposition works with a different signal and wavelet by giving a different perspective on how this technique can be applied to various types of signals −

import numpy as np
import pywt
import matplotlib.pyplot as plt

# Generate a signal (combination of a sine wave and a high-frequency pulse)
t = np.linspace(0, 1, 1000, endpoint=False)  # Time vector
signal = np.sin(2 * np.pi * 30 * t) + 0.5 * np.sin(2 * np.pi * 150 * t)  # Combination of low and high frequencies

# Perform Multi-Level DWT decomposition using the Symlet wavelet (sym2)
coeffs = pywt.wavedec(signal, 'sym2', level=4)

# Extract approximation and detail coefficients for each level
cA4, cD4, cD3, cD2, cD1 = coeffs  # cA4: Approximation at level 4, cD4: Detail at level 4, etc.

# Plot the original signal and the decomposition results
plt.figure(figsize=(10, 12))

# Plot the original signal
plt.subplot(6, 1, 1)
plt.plot(t, signal)
plt.title("Original Signal")
plt.xlabel("Time")
plt.ylabel("Amplitude")

# Plot approximation coefficients at level 4
plt.subplot(6, 1, 2)
plt.plot(cA4)
plt.title("Approximation Coefficients at Level 4")

# Plot detail coefficients at level 4
plt.subplot(6, 1, 3)
plt.plot(cD4)
plt.title("Detail Coefficients at Level 4")

# Plot detail coefficients at level 3
plt.subplot(6, 1, 4)
plt.plot(cD3)
plt.title("Detail Coefficients at Level 3")

# Plot detail coefficients at level 2
plt.subplot(6, 1, 5)
plt.plot(cD2)
plt.title("Detail Coefficients at Level 2")

# Plot detail coefficients at level 1
plt.subplot(6, 1, 6)
plt.plot(cD1)
plt.title("Detail Coefficients at Level 1")

plt.tight_layout()
plt.show()

Below is the output of the Multi-Level Wavelet Decomposition for multi signals −

Multi-Resolution Decomposition for multiple signals

Understanding the Decomposed Components

After performing the decomposition the signal is broken down into the following components −

  • Approximation Coefficients: Represent the low-frequency (coarse) part of the signal.
  • Detail Coefficients: Capture the high-frequency (fine) components at each level.

Applications of Multi-Resolution Decomposition

The Multi-Resolution Decomposition technique is useful in various fields such as −

  • Image Compression: Used in JPEG2000 for progressive image reconstruction.
  • Biomedical Signal Processing: Analyzing ECG and EEG signals for diagnosis.
  • Fault Detection: Identifying faults in machinery through vibration analysis.
  • Time-Series Forecasting: Extracting key features from financial or environmental data.

Choosing the Right Wavelet for MRA

The choice of wavelet function is critical for effective Multi-Resolution Analysis. Some commonly used wavelets and their applications are listed below −

Wavelet Best For Example Use Cases
Daubechies (db) General-purpose smooth signals Signal compression, denoising
Coiflet High vanishing moments, feature detection Biomedical analysis
Haar Simple step-like signals Edge detection, compression

Note: Choosing the appropriate wavelet depends on the characteristics of the signal and the application requirements.

Advertisements