This repository provides a Python package for generating, filtering, fitting, and analyzing signals. The package includes functionalities for creating noisy signals, applying filters, fitting damped sine waves, and performing statistical analysis.
- Generate noisy sine wave signals
- Apply Butterworth low-pass filters
- Fit damped sine waves to filtered signals
- Perform t-tests between filtered signals and fitted models
- Compute and visualize Fourier Transforms
- Create and source virtual environment:
python -m venv env
source env/bin/activate # On Windows use `env\Scripts\activate`
- Install the dependencies:
pip install -r requirements.txt
Using unittest
python -m unittest discover -s tests
An example demonstrating generating a signal, applying filters, fitting models, and performing analysis, exists under examples
directory (refer to run_example.py
)
Note
An example plot has been uploaded to the plots
directory.
Generate a Noisy Signal
import numpy as np
from src.signal_processor import SignalProcessor
timeVector = np.linspace(0, 1, 1000, endpoint = False) # Or consider importing or modifying your time vector
processor = SignalProcessor(timeVector)
processor.generateNoisySignal(frequency = 20, noiseStdDev = 0.6)
# or with defaults:
processor.generateNoisySignal() # frequency = 10, noiseStdDev = 0.5
Apply Butterworth low-pass filter
processor.applyFilter(filterOrder = 2, cutoffFrequency = 0.8)
# or with defaults:
processor.applyFilter() # filterOrder = 4, cutoffFrequency = 0.2
Fit a damped sine wave to the filtered signal
# default sine wave parameters: amplitudeParam = 1.0, frequencyParam = 10.0, phaseParam = 0.0, decayRateParam = 0.1
processor.fitDampedSineWave()
# Or preset with:
processor.setDampedSineWaveParameters(3.0, 12.0, np.pi / 6, 0.3)
processor.setDampedSineWaveBounds([0, 0, -np.pi/2, 0], [10, 20, np.pi/2, 1])
processor.fitDampedSineWave()
Perform a t-test between the filtered signal and the fitted damped sine wave
processor.performTTest()
Plot and save the results (will be saved under plots
directory)
processor.plotResults()
Print the fitting and statistical results
processor.printResults()