An interactive Streamlit web application for performing Continuous Wavelet Transform (CWT) analysis and Fast Fourier Transform (FFT) on signal data, with a focus on Phonocardiogram (PCG) signal analysis.
- Upload Custom Data: Load 2-column
.txtfiles (time and signal values) - Generate Synthetic Signals: Create sine waves with customizable parameters:
- Two independent sine wave components
- Adjustable frequency, amplitude, and noise levels
- Configurable sampling frequency and duration
-
Time-Domain Analysis
- Normalized signal visualization
- Shannon Energy envelope computation
- Interactive plots with zoom capabilities
-
Frequency-Domain Analysis (FFT)
- Fast Fourier Transform using Radix-2 algorithm (implemented from scratch)
- Frequency spectrum visualization
- Magnitude analysis up to Nyquist frequency
-
Time-Frequency Analysis (CWT)
- Continuous Wavelet Transform using Morlet wavelet
- Interactive scalogram visualization (contour plot)
- 3D surface plot of CWT coefficients
- Configurable CWT parameters:
- Morlet ω₀ parameter
- Scale parameters (start, step, count)
- Number of time translations
- Automated Feature Detection: Identify heart sound components (M1, T1, A2, P2)
- Binary Thresholding: Adjustable amplitude threshold for region detection
- Center of Gravity (CoG): Calculate time, frequency, and amplitude for each detected component
- Component Labeling: Automatic labeling and visualization on scalogram
- Python 3.7 or higher
- pip package manager
Install the required packages:
pip install streamlit numpy pandas scipy plotlyOr use the requirements file if available:
pip install -r requirements.txt- Navigate to the project directory:
cd CWT-From-Scratch- Launch the Streamlit app:
streamlit run cwt.py- The application will open in your default web browser (typically at
http://localhost:8501)
- Select "Upload File" in the sidebar
- Upload a
.txtfile with two columns: time and signal values - The sampling frequency will be automatically calculated from the time data
- Adjust CWT parameters as needed
- Select "Generate Sine Wave" in the sidebar
- Configure signal parameters:
- Sampling frequency (Hz)
- Duration (seconds)
- Frequency and amplitude for two sine components
- Noise level
- The signal will be generated automatically
-
Adjust CWT parameters in the sidebar:
- ω₀: Morlet wavelet parameter (default: 2π × 0.849)
- Start Scale (a): Initial scale value
- Scale Step (da): Increment for scale values
- Number of Scales: Resolution in frequency dimension
- Number of Time-Shifts: Resolution in time dimension
-
Click "Compute CWT" to perform the analysis
-
View results:
- CWT scalogram (contour plot)
- Binary mask with threshold adjustment
- Detected PCG components with time, frequency, and amplitude
- Optional 3D surface plot
- Scale-to-frequency and translation-to-time mappings
The application expects a 2-column space or tab-delimited .txt file:
0.0000 0.1234
0.0010 0.2345
0.0020 0.3456
...
Column 1: Time (seconds)
Column 2: Signal amplitude
Sample PCG signal files are included in the data/ directory:
Print_13_v2_PCG_RV.txtPrint_14_v2_PCG_RV.txt
- Wavelet: Complex Morlet wavelet
- Method: Direct convolution in time domain
- Normalization: Energy-preserving normalization
- Output: Magnitude of complex CWT coefficients
- Algorithm: Radix-2 Cooley-Tukey FFT
- Padding: Zero-padding to nearest power of 2
- Scaling: Normalized magnitude spectrum
- Formula: E(t) = -1/N × Σ(x²·log(x² + ε))
- Parameters: Frame length and hop size based on sampling rate
- Output: Energy envelope with mean and standard deviation
- Caching: CWT results are cached using Streamlit's caching mechanism
- Progress Tracking: Real-time progress bar during CWT computation
- Interactive Plots: Plotly-based visualizations with zoom and pan
This tool is particularly useful for:
- Cardiac Signal Analysis: PCG (phonocardiogram) heart sound analysis
- Signal Processing Education: Understanding time-frequency analysis
- Research: Exploring wavelet transform parameters
- Feature Extraction: Identifying signal components in time-frequency domain
- CWT Computation: O(N × M × K) where:
- N = number of scales
- M = number of translations
- K = signal length
- FFT Computation: O(N log N) where N is the padded signal length
- Large parameter combinations (high scale/translation counts) may result in long computation times
- Memory usage scales with the product of scales and translations
- CWT is computed in the time domain (not optimized with FFT-based convolution)
This project is open-source and available for educational and research purposes.
Created as part of signal processing and biomedical engineering research.
- Wavelet theory and Morlet wavelet implementation
- PCG signal analysis methodology
- Streamlit framework for interactive web applications