I am new to the topic of compressed sensing. I read a few papers about it by R.Baranuik, Y.Eldar, Terence Tao etc. All these papers basically provide the mathematical details behind it, i.e., Sparsity, RIP, L1 norm minimisation etc. However, can anyone provide the MATLAB codes that achieve compressive sensing?

Thanks in advance for any help.

  • 1
    $\begingroup$ Requests for code are off-topic here. $\endgroup$ – pichenettes Aug 10 '13 at 20:31
  • Most of the code is plain Matlab code
  • Each folder in the package consists of a CS recovery algorithm based on a particular signal model, and a script that tests that recovery algorithm. The names of the scripts typically end with '_example.m'
  • Manopt. Possibly what you use to actually make the algorithms included in other toolboxes.

Optimization on manifolds is a powerful paradigm to address nonlinear optimization problems.

This toolbox implements several algorithms to compute sparse expansion in redundant dictionaries and to solve inverse problems with sparse regularization (and also TV regularization).

But all of that, and more, is included in this list of toolboxes.

I've found the hard part is finding psuedocode -- that's where they actually describe the algorithm. Here are some examples of algorithms that included the psuedocode:


I suppose I am answering off-topic here then, but for L1-optimization approaches, I find YALL1 (http://yall1.blogs.rice.edu/) and SPGL1 (http://www.cs.ubc.ca/~mpf/spgl1/) very useful and efficient packages. TFOCS (http://cvxr.com/tfocs/) is probably a bit harder to use, but should be quite flexible. There is also CVX (http://cvxr.com/cvx/) which makes it very easy to type convex optimization problems directly into the code, but it is considerably slower for solving the compressed sensing-specific kind of problems since it is a very general solver.

There are also some reconstruction algorithms available in Sparselab (http://sparselab.stanford.edu/).

A larger list of sparse reconstruction codes is listed here: https://sites.google.com/site/igorcarron2/cs#reconstruction


Keep in mind, L1 is not the only approach to compressive sensing. In our research, we've had better success with Approximate Message Passing (AMP). I am defining "success" as lower error, better phase transitions (ability to recover with fewer observations), and lower complexity (both memory and cpu).

The Approximate Message Passing algorithm establishes a Bayesian framework to estimate the unknown vectors in a large scale linear system where the inputs and outputs of the linear system are determined by probablistic models (e.g. "this vector was measured with noise", "this vector has some zeros"). The original AMP approach forged by Donoho has been refined by Rangan into Generalized Approximate Message Passing with Matlab code available. The inputs and outputs can be almost arbitrary probability density functions. In our research , we've found that GAMP is typically faster, more accurate, and more robust (read: better phase transition curves) than the L1 convex approaches and greedy approaches (e.g. Orthogonal Matching Pursuit).

My advisor and I just wrote a paper on using GAMP for Analysis CS, where one expects an abundance of zeros, not in the unknown vector x, but rather in a linear function of that unknown, Wx.


You may also want to check the Matlab UNLocBox: http://unlocbox.sourceforge.net There are 4 compressive sensing scripts on the demo page: http://unlocbox.sourceforge.net/doc/demos/index.php


I have written a number of hands on coding tutorials explaining basics of CS, MP, OMP etc. for beginners. You may check them out at https://sparse-plex.readthedocs.io/en/latest/demos/index.html

It's part of my library sparse-plex available at GitHub https://github.com/indigits/sparse-plex


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.