Skip to content

infocusp/signal_alignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

signal_alignment

The signal_alignment is a Python-based repository for aligning and synchronizing time-series signals using various methods, including Cross-Correlation, Mean Squared Error (MSE), MSE with Threshold, and advanced techniques combining Local Phase Variance (LPV) and FFT-based approaches. The toolkit provides modular code for signal generation, alignment, and visualization, with both a command-line script and a Jupyter Notebook to demonstrate its functionality.

Repository Structure

signal_alignment/
├── modules/
│   ├── cross_correlation.py        # Cross-Correlation alignment method
│   ├── mse_alignment.py            # MSE-based alignment method
│   ├── mse_fft_lpv_alignment.py    # MSE with FFT and LPV alignment
│   ├── mse_lpv_alignment.py        # MSE with LPV alignment
│   ├── mse_threshold_alignment.py  # MSE with threshold alignment
│   ├── plot_utils.py               # Utilities for plotting signals
│   ├── signal_utils.py             # Utilities for signal generation
├── results/                        # Directory for output plots (created at runtime)
├── main.py                         # Main script to run alignment methods
├── SignalAlignment.ipynb           # Jupyter Notebook showcasing code execution
├── requirements.txt                # Python dependencies

Features

  • Signal Generation: Generate base and derived signals with customizable frequencies, amplitudes, phase variations, and noise.
  • Alignment Methods:
    • Cross-Correlation
    • Mean Squared Error (MSE)
    • MSE with Threshold
    • MSE with Local Phase Variance (LPV)
    • MSE with FFT and LPV
  • Visualization: Save aligned signal plots as PNG files in the results directory.
  • Modular Design: Reusable classes for signal processing and alignment.
  • Interactive Demo: A Jupyter Notebook (SignalAlignment.ipynb) showcases the execution of signal generation and alignment methods.

Installation

  1. Clone the Repository:

    git clone https://github.com/infocusp/signal_alignment.git
    cd signal_alignment
  2. Create a Virtual Environment (optional but recommended):

    python -m venv myenv
    source myenv/bin/activate  # On Windows: myenv\Scripts\activate
  3. Install Dependencies: Ensure you have Python 3.8+ installed, then run:

    pip install -r requirements.txt

    The requirements.txt includes dependencies like numpy, plotly, scipy, and jupyter for the notebook.

Usage

Command-Line Execution

The main.py script demonstrates the toolkit’s functionality by generating signals, applying all alignment methods, and saving plots to the results directory.

  1. Run the Main Script:

    python main.py
  2. What It Does:

    • Generates a base signal with frequencies [0.5, 3, 2, 6], amplitudes [0.5, 1, 3, 5], and phase variations [True, True, False, True].
    • Creates two derived signals with added noise (noise_scale=0.05).
    • Crops signals randomly within a specified range (crop_range=(0.75, 0.8)).
    • Applies five alignment methods: MSE+LPV, MSE, Cross-Correlation, MSE+FFT LPV, and MSE with Threshold.
    • Saves visualization plots as PNG files in the results directory.
  3. Output:

    • Console output indicates the success or failure of each alignment method.
    • Plots of aligned signals are saved in the results directory (e.g., mse_lpv_alignment.png, cross_correlation.png).

Jupyter Notebook

The SignalAlignment.ipynb notebook provides an interactive environment to explore and experiment.

  1. Launch Jupyter Notebook:

    jupyter notebook SignalAlignment.ipynb
  2. What It Includes:

    • Step-by-step execution of signal generation and alignment methods.
    • Visualizations of base, derived, and aligned signals.
    • Example code mirroring main.py with interactive outputs.

Example

To customize the signal parameters, modify main.py or the notebook. For example, to change the sampling frequency and noise level:

sg = SignalGenerator(fs=200, duration_sec=3.0)  # Update sampling frequency and duration
t, s1, s2 = sg.generate_derived_signals(base_signal, noise_scale=0.1)  # Increase noise

Run the script or notebook again to see updated results:

python main.py
# OR open SignalAlignment.ipynb in Jupyter

Requirements

The requirements.txt includes:

numpy
plotly
scipy
jupyter

Install them using pip install -r requirements.txt.

Contributing

Contributions are welcome! Please:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/new-alignment).
  3. Commit your changes (git commit -m "Add new alignment method").
  4. Push to the branch (git push origin feature/new-alignment).
  5. Open a pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •