View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Matching pursuit for 1D signals

5.0 | 1 rating Rate this file 40 Downloads (last 30 days) File Size: 4.82 KB File ID: #32426 Version: 1.3
image thumbnail

Matching pursuit for 1D signals



03 Aug 2011 (Updated )

Performs Matching Pursuit on 1d (temporal) signals with custom basis

| Watch this File

File Information

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 (

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))).

Function signature:
 [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
Example use:
  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


Fft Based Convolution inspired this file.

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
03 Apr 2015 chen huaming

r = sum_i conv(ws(:,i),B(:,i),'same') ?It is right?

04 Aug 2011 1.1

Corrected bug with edges, increase efficiency by adding a level to the current maximum correlation search tree

22 Sep 2011 1.3

Added "deadzone" feature

Contact us