Awesome
Python Signal Processing
This repository contains tutorials on understanding and applying signal processing using NumPy and PyTorch.
splearn is a package for signal processing and machine learning with Python. It is built on top of NumPy and SciPy, to provide easy to use functions from common signal processing tasks to machine learning.
Contents
Tutorials
Signal processing can be daunting; we aim to bridge the gap for anyone who are new signal processings to get started, check out the tutorials to get started on signal processings.
1. Signal composition (time, sampling rate and frequency)
In order to begin the signal processing adventure, we need to understand what we are dealing with. In the first tutorial, we will uncover what is a signal, and what it is made up of. We will look at how the sampling rate and frequency can affect a signal. We will also see what happens when we combine multiple signals of different frequencies.
2. Fourier Transform
Now we know what are signals made of and we learned that combining multiple signals of various frequencies will jumbled up all the frequencies. In this tutorial, we will learn about Fourier Transform and how it can take a complex signal and decompose it to the frequencies that made it up.
3. Denoising with mean-smooth filter
We know that signals can be noisy, and this tutorial will focus on removing these noise. We learn to apply the simplest filter to perform denoising, the running mean filter. We will also understand what are edge effects.
4. Denoising with Gaussian-smooth filter
Next, we will look at a slight adaptation of the mean-smooth filter, the Gaussian smoothing filter. This tends to smooth the data to be a bit smoother compared to mean-smooth filter. This does not mean that one is better than the other, it depends on the specific applications. So, it is important to be aware of different filters type and how to use them.
5. Canonical correlation analysis
Canonical correlation analysis (CCA) is applied to analyze the frequency components of a signal. In this tutorials, we use CCA for feature extraction and classification.
6. Task-related component analysis
Task-related component analysis (TRCA) is a classification method originally for steady-state visual evoked potentials (SSVEPs) detection.
Getting Started
Installation
Currently, this has not been released. Use git clone
, and install the dependencies:
git clone https://github.com/jinglescode/python-signal-processing.git
pip install -r requirements.txt
Dependencies, see requirements.txt.
Usage
Let's generate a 2D-signal, sampled at 100-Hz. Design and apply a 4th-order bandpass Butterworth filter with a cutoff frequency between 5-Hz and 20-Hz.
from splearn.data.generate import generate_signal
from splearn.filter.butter import butter_bandpass
signal_2d = generate_signal(
length_seconds=4,
sampling_rate=100,
frequencies=[[4,7,11,17,40, 50],[1, 3]],
plot=True
)
signal_2d_filtered = butter_bandpass(
signal=signal_2d,
lowcut=5,
highcut=20,
sampling_rate=100,
type='sos',
order=4,
plot=True,
plot_xlim=[3,20]
)
See examples for more examples.
Datasets
Some dataset extraction code are provided, see examples to see how to use them.
- BETA: A Large Benchmark Database Toward SSVEP-BCI Application
- A Benchmark Dataset for SSVEP-Based Brain–Computer Interfaces
- A Comparison Study of Canonical Correlation Analysis Based Methods for Detecting Steady-State Visual Evoked Potentials
- EEG dataset and OpenBMI toolbox for three BCI paradigms: an investigation into BCI illiteracy.
Disclaimer on Datasets
We do not host or distribute these datasets, vouch for their quality or fairness, or claim that you have license to use the dataset. It is your responsibility to determine whether you have permission to use the dataset under the dataset's license.
If you're a dataset owner and wish to update any part of it (description, citation, etc.), or do not want your dataset to be included in this library, please get in touch through a GitHub issue. Thanks for your contribution to the ML community!
Methods
A few methods have been included as they have been tested (within my limited time). They are by no means recommended or exhaustive.
- Compact-CNN
- Canonical Correlation Analysis (CCA)
- Task-Related Component Analysis (TRCA)
- Multi-Task SSVEP
- Convolutional correlation analysis for enhancing the performance of SSVEP-based brain-computer interface
- Time-domain-based CNN method (tCNN)
If you wish to include your model, you are welcome to do so via pull request. Do check out how other models are implemented for reference. PyTorch models and sklearn/numpy methods only.