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.
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
- 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.
-
Clone the Repository:
git clone https://github.com/infocusp/signal_alignment.git cd signal_alignment
-
Create a Virtual Environment (optional but recommended):
python -m venv myenv source myenv/bin/activate # On Windows: myenv\Scripts\activate
-
Install Dependencies: Ensure you have Python 3.8+ installed, then run:
pip install -r requirements.txt
The
requirements.txt
includes dependencies likenumpy
,plotly
,scipy
, andjupyter
for the notebook.
The main.py
script demonstrates the toolkit’s functionality by generating signals, applying all alignment methods, and saving plots to the results
directory.
-
Run the Main Script:
python main.py
-
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.
- Generates a base signal with frequencies
-
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
).
The SignalAlignment.ipynb
notebook provides an interactive environment to explore and experiment.
-
Launch Jupyter Notebook:
jupyter notebook SignalAlignment.ipynb
-
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.
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
The requirements.txt
includes:
numpy
plotly
scipy
jupyter
Install them using pip install -r requirements.txt
.
Contributions are welcome! Please:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/new-alignment
). - Commit your changes (
git commit -m "Add new alignment method"
). - Push to the branch (
git push origin feature/new-alignment
). - Open a pull request.