Skip to main content

Dual Dynamic Kernel Filtering (2DKF) — minimal package

Project description

ddkf

Minimal package providing 2DKF for time-frequency decomposition and a denoise convenience function. Available to install with pip as package ddkf.

Quick install

python3 -m pip install ddkf

Full example (runnable)

The following example produces plots highlighting time frequency representation and denoising. Copy it into a file (e.g. run_example.py) or run interactively.

import numpy as np
import matplotlib.pyplot as plt
from ddkf import ddkf, denoise

if __name__ == "__main__":
    print("=" * 70)
    print("2DKF Example: Noisy Signal Decomposition and Recovery")
    print("=" * 70)
    
    # Initialize
    step_size = 4
    c_smoothing = 0.12
    c_smart_min = 0.9
    window_size = 20
    Fs = 100  # Sampling frequency
    t = np.arange(0, 5, 1/Fs)  # Time vector (5 seconds)
    
    # Generate signal: 3 Hz + 7 Hz mixed sine wave
    print("Generating test signal (3 Hz + 7 Hz with Gaussian noise)...")
    signal = np.sin(2*np.pi*3*t) + 0.5*np.sin(2*np.pi*7*t)
    signal = signal + 0.2*np.random.randn(len(signal))  # Add Gaussian noise
    
    # Create 2DKF instance with hybrid kernel
    print("Applying 2DKF with hybrid kernel...")
    dkf = ddkf(
        window_size=window_size,
        step_size=step_size,
        alpha=c_smart_min,      # c_smart_min in original
        beta=c_smoothing,       # c_smoothing in original
        kernel='hybrid',
        kernel_params={'gamma': 0.5}  # Equal weighting
    )
    
    # Fit and transform
    dkf.fit(signal)
    recovered = dkf.inverse_transform(correction_factor=c_smart_min)
    
    # Get time-frequency representation
    tfr = dkf.get_tfr()
    
    print(f"Original signal shape: {signal.shape}")
    print(f"Interpolated signal shape: {dkf.signal_values_.shape}")
    print(f"TFR shape: {tfr.shape}")
    print(f"Recovered signal shape: {recovered.shape}")
    
    # Create plots
    print("Generating plots...")
    
    # Figure 1: 2DKF Module Image
    import matplotlib.pyplot as plt
    plt.figure(figsize=(10, 6))
    plt.imshow(tfr, aspect='auto', cmap='viridis')
    plt.colorbar(label='Magnitude')
    plt.title('2DKF Module Image (Time-Frequency Representation)')
    plt.xlabel('Frequency bins')
    plt.ylabel('Time windows')
    plt.tight_layout()
    
    # Figure 2: Comparison plot
    plt.figure(figsize=(12, 6))
    
    # Plot original noisy signal
    plt.subplot(2, 1, 1)
    plt.plot(signal, 'r-', alpha=0.6, linewidth=0.8, label='Original noisy signal')
    plt.title('Original Noisy Signal')
    plt.xlabel('Sample')
    plt.ylabel('Amplitude')
    plt.grid(True, alpha=0.3)
    plt.legend()
    
    # Plot recovered signal (adjusted to match original length for comparison)
    plt.subplot(2, 1, 2)
    plt.plot(recovered, 'b-', linewidth=1.5, label='Recovered signal')
    plt.title('Recovered Signal (Denoised)')
    plt.xlabel('Sample (time windows)')
    plt.ylabel('Amplitude')
    plt.grid(True, alpha=0.3)
    plt.legend()
    
    plt.tight_layout()
    
    print("All plots generated successfully!")
    print("Closing plots will end the program...")
    plt.show()
    
    print("" + "=" * 70)
    print("2DKF processing complete")
    print("=" * 70)

Reference

If you use this package or the underlying 2DKF technique in your research or software, please cite the original work:

@article{bensegueni2025dual,
  title={Dual Dynamic Kernel Filtering: Accurate Time-Frequency Representation, Reconstruction, and Denoising},
  author={Bensegueni, Skander and Belhaouari, Samir Brahim and Kahalan, Yunis Carreon},
  journal={Digital Signal Processing},
  pages={105407},
  year={2025},
  publisher={Elsevier}
}

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ddkf-0.3.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ddkf-0.3.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file ddkf-0.3.0.tar.gz.

File metadata

  • Download URL: ddkf-0.3.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ddkf-0.3.0.tar.gz
Algorithm Hash digest
SHA256 39114f9efa2ac01b8e4e16a9db7737a46ad083668b063b1efccb2e39dd5304cc
MD5 80257adf55205c0ee6c481c1fe3d3100
BLAKE2b-256 2986141e554732e82ea8e686a302698d6b68620927a8ef94a1c38b1ecefc59f1

See more details on using hashes here.

File details

Details for the file ddkf-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ddkf-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ddkf-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 751b266c1ef5cbc9cc2d0a3703641b037db776c70241a47f289d9f2127915f8b
MD5 3bd36c22c4f3aca943da94b44fc0bbad
BLAKE2b-256 3673da2c68453ccbf7d6f770c145c8cccf389cd563e650b02d79634d270790b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page