Performs matching pursuit (MP) on a one-dimensional (temporal) signal y with a custom basis B.
Matching pursuit (Mallat and Zhang 1993) is a greedy algorithm to obtain a sparse representation of a signal y in terms of a weighted sum (w) of dictionary elements D (y ~ Dw). Sparse means that most elements are equal to 0 (nnz(w) << length(y)). Such a sparse representation is useful in many different scenarios: to obtain time-frequency spectrograms, denoise signals, compress signals, etc.
For temporal signals, it's natural to use a dictionary of elements D composed of basis elements B shifted to every possible time point. In this case, the weights form of a convolutional or shift-invariant sparse code in a highly overcomplete dictionary:
y ~ r
r = sum_i conv(ws(:,i),B(:,i),'same')
and nnz(ws(:)) << length(y)
If B is equal to a bunch of windowed sinusoids, this representation forms a time-frequency decomposition of the signal. One application of this decomposition is EEG/MEG and LFP analysis (http://www.scholarpedia.org/article/Matching_pursuit).
Another application is expressing a sound signal as a sum of gammatone-like functions (Smith and Lewicki 2006) or chords (Blumensath and Davies 2006).
This implementation should be efficient enough for practical use. It precomputes all convolutions using the FFT and does not perform convolutions in the main loop. It uses a 3-level tree to search for the maximum correlation, and each iteration is O(sqrt(length(y))).
[ws,r] = temporalMP(y,B,nonnegative,maxiter,maxr2)
y: a mx1 signal
B: an nxp basis. n is the length of each basis function and p is
the number of such basis functions
nonnegative (optional): if true, uses a variant of MP where ws are
forced to be >= 0 (default false)
maxiter and maxr2 (optional): specifies when to stop iterating,
when #iterations > maxiter or the R^2 between y and r
is greater than maxr, whichever comes first (defaults: maxiter:
10000, maxr2: .999)
ws: an mxn matrix of weights
r: the approximation of y in terms of the weights and basis
sig = load('gong.mat'); %included in matlab
%Build a basis of Gabors
rg = (-500:500)';
sigmas = exp(log(2):.3:log(200));
gabors = exp(-.5*(rg.^2)*sigmas.^(-2)).*cos(rg*sigmas.^(-1)*2*pi*2);
%Express signal as a sparse sum of Gabors
[ws,r] = temporalMP(sig.y,gabors,false,5000);
%See TryTemporalMP.m for more examples
Patrick Mineault (2020). Matching pursuit for 1D signals (https://www.mathworks.com/matlabcentral/fileexchange/32426-matching-pursuit-for-1d-signals), MATLAB Central File Exchange. Retrieved .
Added "deadzone" feature
Corrected bug with edges, increase efficiency by adding a level to the current maximum correlation search tree
Inspired by: FFT-based convolution