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.4.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.4.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ddkf-0.4.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.4.0.tar.gz
Algorithm Hash digest
SHA256 3f6e2e11455e59e531b70f62ce76bdf4f050e257c0e01c8cfc2f0f366c05fe27
MD5 b73783235e7e7578dd07b15063cebf46
BLAKE2b-256 338f5c9de8809c1f9722b1abc20784771b7f39b1f403f8ed97adead57ff47728

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ddkf-0.4.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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dda86e393b53f8b885b789afc11abcc0a7cfd7c0b418bc929ee9653452b2c449
MD5 f7e017c92efd70b475de55c11f9f4225
BLAKE2b-256 e2f5b4062d37ae6d28b201dedb2f4660c0879575a01eb56bce848652e8eb8673

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