CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pywavelets

Discrete and continuous wavelet transforms for signal and image processing with comprehensive 1D, 2D, and nD transform support.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

wavelets.mddocs/

Wavelet Objects and Utilities

Core wavelet objects, discovery functions, and utility functions for wavelet analysis including frequency analysis and filter bank operations.

Capabilities

Wavelet Discovery

Functions to explore available wavelets and families supported by PyWavelets.

def wavelist(family: str = None, kind: str = 'all') -> list:
    """
    List available wavelets.
    
    Parameters:
    - family: Wavelet family ('haar', 'db', 'sym', 'coif', 'bior', 'rbio', 'dmey', 'gaus', 'mexh', 'morl', 'cgau', 'shan', 'fbsp', 'cmor') or None for all families
    - kind: Type of wavelets ('all', 'continuous', 'discrete')
    
    Returns:
    List of available wavelet names
    """

def families(short: bool = True) -> list:
    """
    List available wavelet families.
    
    Parameters:
    - short: Return short family names if True, long names if False
    
    Returns:
    List of wavelet family names
    """

Usage Examples

import pywt

# List all available wavelets
all_wavelets = pywt.wavelist()
print(f"Total wavelets: {len(all_wavelets)}")

# List Daubechies wavelets
db_wavelets = pywt.wavelist('db')
print(f"Daubechies wavelets: {db_wavelets}")

# List only continuous wavelets
continuous = pywt.wavelist(kind='continuous')
print(f"Continuous wavelets: {continuous}")

# List wavelet families
families = pywt.families()
print(f"Wavelet families: {families}")

Discrete Wavelet Objects

The primary class for working with discrete wavelets, providing access to filter coefficients and wavelet properties.

class Wavelet:
    def __init__(self, name: str, filter_bank=None):
        """
        Discrete wavelet object.
        
        Parameters:
        - name: Wavelet name ('haar', 'db1', 'db2', ..., 'db45', 'sym2', ..., 'sym20', etc.)
        - filter_bank: Custom filter bank as (dec_lo, dec_hi, rec_lo, rec_hi) tuple
        """
    
    # Properties
    name: str  # Wavelet name
    family_name: str  # Full family name
    short_family_name: str  # Short family name
    dec_lo: np.ndarray  # Decomposition low-pass filter
    dec_hi: np.ndarray  # Decomposition high-pass filter  
    rec_lo: np.ndarray  # Reconstruction low-pass filter
    rec_hi: np.ndarray  # Reconstruction high-pass filter
    dec_len: int  # Decomposition filter length
    rec_len: int  # Reconstruction filter length
    orthogonal: bool  # True if orthogonal wavelet
    biorthogonal: bool  # True if biorthogonal wavelet
    symmetry: str  # Symmetry type ('asymmetric', 'near symmetric', 'symmetric')
    vanishing_moments_psi: int  # Vanishing moments of wavelet function
    vanishing_moments_phi: int  # Vanishing moments of scaling function
    filter_bank: tuple  # (dec_lo, dec_hi, rec_lo, rec_hi)
    inverse_filter_bank: tuple  # Inverse filter bank
    
    def wavefun(self, level: int = 8):
        """
        Compute wavelet and scaling functions.
        
        Parameters:
        - level: Decomposition level (higher = more detailed)
        
        Returns:
        For orthogonal wavelets: (psi, x) - wavelet function and x coordinates
        For biorthogonal wavelets: (psi_d, psi_r, x) - decomposition and reconstruction wavelets with x coordinates
        For scaling functions: (phi, psi, x) or (phi_d, psi_d, phi_r, psi_r, x)
        """

Usage Examples

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

# Create Daubechies-4 wavelet
db4 = pywt.Wavelet('db4')
print(f"Name: {db4.name}")
print(f"Family: {db4.family_name}")
print(f"Orthogonal: {db4.orthogonal}")
print(f"Filter length: {db4.dec_len}")
print(f"Vanishing moments: {db4.vanishing_moments_psi}")

# Access filter coefficients
print(f"Low-pass filter: {db4.dec_lo}")
print(f"High-pass filter: {db4.dec_hi}")

# Compute and plot wavelet function
phi, psi, x = db4.wavefun(level=8)
plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(x, phi)
plt.title('Scaling function (φ)')
plt.subplot(1, 2, 2)  
plt.plot(x, psi)
plt.title('Wavelet function (ψ)')
plt.show()

# Biorthogonal wavelet example
bior = pywt.Wavelet('bior2.2')
phi_d, psi_d, phi_r, psi_r, x = bior.wavefun()
print(f"Biorthogonal: {bior.biorthogonal}")

Continuous Wavelet Objects

Class for continuous wavelets used in continuous wavelet transforms (CWT).

class ContinuousWavelet:
    def __init__(self, name: str, dtype=np.float64):
        """
        Continuous wavelet object.
        
        Parameters:
        - name: Continuous wavelet name ('gaus1'-'gaus8', 'mexh', 'morl', 'cgau1'-'cgau8', 'shan', 'fbsp', 'cmor')
        - dtype: Data type for computations
        """
    
    # Properties  
    name: str  # Wavelet name
    family_name: str  # Full family name
    short_family_name: str  # Short family name
    complex_cwt: bool  # True if CWT produces complex output
    lower_bound: float  # Lower support bound
    upper_bound: float  # Upper support bound  
    center_frequency: float  # Center frequency
    bandwidth_frequency: float  # Bandwidth frequency
    fbsp_order: int  # B-spline order (for 'fbsp' wavelets)
    
    def wavefun(self, level: int = 8, length: int = None):
        """
        Compute continuous wavelet function.
        
        Parameters:
        - level: Resolution level
        - length: Length of the wavelet function
        
        Returns:
        (psi, x) - wavelet function values and x coordinates
        """

Usage Examples

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

# Mexican hat wavelet
mexh = pywt.ContinuousWavelet('mexh')
print(f"Name: {mexh.name}")
print(f"Complex CWT: {mexh.complex_cwt}")
print(f"Center frequency: {mexh.center_frequency}")

# Compute wavelet function
psi, x = mexh.wavefun()
plt.figure(figsize=(8, 4))
plt.plot(x, psi)
plt.title('Mexican Hat Wavelet')
plt.xlabel('x')
plt.ylabel('ψ(x)')
plt.grid(True)
plt.show()

# Complex Morlet wavelet
morlet = pywt.ContinuousWavelet('morl')
psi, x = morlet.wavefun()
plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(x, np.real(psi), label='Real')
plt.plot(x, np.imag(psi), label='Imaginary')
plt.title('Morlet Wavelet')
plt.legend()
plt.subplot(1, 2, 2)
plt.plot(x, np.abs(psi))
plt.title('Morlet Wavelet (Magnitude)')
plt.show()

Wavelet Factory Function

Convenience function that returns the appropriate wavelet object type.

def DiscreteContinuousWavelet(name: str, filter_bank=None):
    """
    Factory function returning appropriate Wavelet or ContinuousWavelet object.
    
    Parameters:
    - name: Wavelet name
    - filter_bank: Custom filter bank for discrete wavelets
    
    Returns:
    Wavelet object for discrete wavelets or ContinuousWavelet object for continuous wavelets
    """

Signal Extension Modes

Constants and utilities for handling signal boundaries during transforms.

class Modes:
    """Signal extension modes for boundary handling."""
    zero: str = 'zero'  # Zero padding
    constant: str = 'constant'  # Constant padding
    symmetric: str = 'symmetric'  # Symmetric extension
    reflect: str = 'reflect'  # Reflection at boundaries
    periodic: str = 'periodic'  # Periodic extension
    smooth: str = 'smooth'  # Smooth padding
    periodization: str = 'periodization'  # Periodization
    antisymmetric: str = 'antisymmetric'  # Antisymmetric extension
    antireflect: str = 'antireflect'  # Antireflection
    
    @staticmethod
    def from_object(mode) -> str:
        """
        Convert mode object to mode string.
        
        Parameters:
        - mode: Mode specification (string, integer, or Mode constant)
        
        Returns:
        Mode string
        """

Wavelet Analysis Functions

Utility functions for analyzing wavelet properties and frequency characteristics.

def integrate_wavelet(wavelet, precision: int = 8):
    """
    Integrate wavelet function from -∞ to x.
    
    Parameters:
    - wavelet: Wavelet instance or name
    - precision: Precision level for wavelet function approximation
    
    Returns:
    For orthogonal wavelets: (int_psi, x)
    For biorthogonal wavelets: (int_psi_d, int_psi_r, x)
    """

def central_frequency(wavelet, precision: int = 8) -> float:
    """
    Compute central frequency of wavelet function.
    
    Parameters:
    - wavelet: Wavelet instance or name  
    - precision: Precision level for wavelet function approximation
    
    Returns:
    Central frequency value
    """

def scale2frequency(wavelet, scale: float, precision: int = 8) -> float:
    """
    Convert CWT scale to normalized frequency.
    
    Parameters:
    - wavelet: Wavelet instance or name
    - scale: CWT scale value
    - precision: Precision level for wavelet function approximation
    
    Returns:
    Normalized frequency (1.0 = sampling frequency)
    """

def frequency2scale(wavelet, freq: float, precision: int = 8) -> float:
    """
    Convert normalized frequency to CWT scale.
    
    Parameters:
    - wavelet: Wavelet instance or name
    - freq: Normalized frequency
    - precision: Precision level for wavelet function approximation
    
    Returns:
    CWT scale value
    """

Filter Bank Operations

Functions for working with wavelet filter banks and creating custom wavelets.

def qmf(filt: np.ndarray) -> np.ndarray:
    """
    Compute Quadrature Mirror Filter (QMF).
    
    Parameters:
    - filt: Input filter coefficients
    
    Returns:
    QMF coefficients with mirror image magnitude response
    """

def orthogonal_filter_bank(scaling_filter: np.ndarray) -> tuple:
    """
    Generate orthogonal filter bank from scaling filter.
    
    Parameters:
    - scaling_filter: Scaling filter coefficients (must have even length)
    
    Returns:
    (dec_lo, dec_hi, rec_lo, rec_hi) - decomposition and reconstruction filter bank
    """

Usage Examples

import pywt
import numpy as np

# Analyze wavelet frequency characteristics
db4 = pywt.Wavelet('db4')
central_freq = pywt.central_frequency(db4)
print(f"Central frequency: {central_freq}")

# Convert between scales and frequencies for CWT
mexh = pywt.ContinuousWavelet('mexh')
scale = 10
freq = pywt.scale2frequency(mexh, scale)
print(f"Scale {scale} corresponds to frequency {freq}")

back_to_scale = pywt.frequency2scale(mexh, freq)
print(f"Frequency {freq} corresponds to scale {back_to_scale}")

# Create QMF from scaling filter
scaling_filter = db4.dec_lo
qmf_filter = pywt.qmf(scaling_filter)
print(f"Original filter: {scaling_filter}")
print(f"QMF filter: {qmf_filter}")

# Generate complete orthogonal filter bank
dec_lo, dec_hi, rec_lo, rec_hi = pywt.orthogonal_filter_bank(scaling_filter)
print(f"Decomposition filters - Lo: {len(dec_lo)}, Hi: {len(dec_hi)}")
print(f"Reconstruction filters - Lo: {len(rec_lo)}, Hi: {len(rec_hi)}")

Types

# Wavelet specifications
WaveletSpec = Union[str, Wavelet, ContinuousWavelet]

# Filter bank format  
FilterBank = Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]  # (dec_lo, dec_hi, rec_lo, rec_hi)

# Extension modes
Mode = Literal[
    'zero', 'constant', 'symmetric', 'periodic', 
    'smooth', 'periodization', 'reflect', 
    'antisymmetric', 'antireflect'
]

Install with Tessl CLI

npx tessl i tessl/pypi-pywavelets

docs

coefficient-utils.md

continuous-dwt.md

index.md

multi-level-dwt.md

multiresolution-analysis.md

single-level-dwt.md

stationary-dwt.md

thresholding.md

wavelet-packets.md

wavelets.md

tile.json