Signal processing from scratch
From complex numbers to wavelets — the Fourier transform, the FFT, convolution, FIR and IIR filters, denoising, resampling and time-frequency analysis, in Python and MATLAB.
A signal is a list of numbers measured over time: a microphone, an ECG, a seismometer, a stock price. Signal processing asks two questions of it — what frequencies are in it? and how do I keep the parts I want and remove the rest? Almost every answer goes through one idea: any signal is a sum of rotating complex numbers, and the Fourier transform tells you how much of each.
This course builds that idea from complex arithmetic upward, then spends it on filters, denoising, resampling and time-frequency maps. Eleven of the thirteen lessons have a live animation, several in the spirit of 3Blue1Brown: winding a signal around a circle, drawing a square wave with spinning circles, and a 3D landscape of a filter over the complex plane.
Prerequisites
- Comfort with sines, cosines and sums. The linear algebra course helps for the matrix view of the DFT, but is not required.
- Basic Python with NumPy. Some scripts are MATLAB; each lesson explains them and the numbers quoted were checked with NumPy ports.
Running the code
git clone https://github.com/prajolshrestha/Signal-Processing-problems.git
cd Signal-Processing-problems/DFT
pip install numpy scipy matplotlib
python 2_DFT_magnitude.py
The Python folders each carry a mysignals.py with the sample data (a 1 kHz + 15 kHz test signal sampled at 48 kHz, a synthetic ECG and a 29-tap impulse response), so every script runs on its own. The MATLAB scripts under Advanced_Signal_processing/ run in MATLAB or, mostly unchanged, in GNU Octave.
A note on data
Many of the advanced MATLAB scripts load recorded datasets — EEGrestingState.mat, emg4TKEO.mat, lineNoiseData.mat and eleven others — that are not in the repository, so those scripts stop at their first line. The lessons work around this by using the data that is there (an earthquake recording and a Google Trends series) and synthetic signals with the same character.
Lessons
- 1 Complex numbers as rotationsWhy signal processing runs on complex numbers — multiplying by e^{iθ} is turning, and a turning arrow casts a sine wave.
- 2 Signals, sampling and aliasingA digital signal is a list of samples. Sample too slowly and a fast wave masquerades as a slow one.
- 3 The discrete Fourier transformWind the signal around a circle at every frequency and watch where its centre of mass goes. That is the DFT.
- 4 The inverse DFT and Fourier seriesRebuilding a signal from its spectrum — spinning circles that draw a square wave, and a sign error that runs time backwards.
- 5 The fast Fourier transformThe same transform with N log N work instead of N² — the butterfly that made digital signal processing practical.
- 6 Convolution and correlationFlip, slide, multiply, sum — the one operation behind every filter, and why it becomes a simple product in the frequency domain.
- 7 FIR filters and windowsDesign a filter by truncating the ideal one — and choose a window to control what the truncation costs.
- 8 IIR filters, poles and zerosFilters with feedback — sharper for the same cost, described by poles and zeros, and best understood as a landscape over the complex plane.
- 9 Zero-phase filteringEvery causal filter delays the signal. Filtering forwards and then backwards cancels the delay — and needs care at the edges.
- 10 Denoising and outliersMean, Gaussian and median smoothing, detrending, the Teager–Kaiser energy operator, and how to find the samples that do not belong.
- 11 Resampling and interpolationChanging the sampling rate without inventing or folding frequencies — low-pass before you downsample, interpolate with care when you upsample.
- 12 Spectral analysis in practiceWelch's method for stable spectra, spectrograms for changing ones, and what a trend does to a spectrum — on an earthquake record and twenty years of search interest.
- 13 Wavelets and time-frequency analysisShort, localised waves that ask "how much of this frequency, right now?" — the Morlet wavelet and the scalogram.