01 April 2013

Example of Compressive Sensing using Matlab

% l1eq example using linprog
% (l1 minimization with equality constraints).

%%%%%%%%%%%%%%%%%%%%%%%%
% Problem definition
% minimise    t(1) + ... + t(n)
% subject to  A*x = b
%             -x - t <= 0
%              x - t <= 0
%%%%%%%%%%%%%%%%%%%%%%%%

clear all
close all

% creating a signal
% signal length
N = 512;
% number of spikes in the signal
T = 20;
% number of observations to make
K = 120;

% random +/- 1 signal
x = zeros(N,1);
q = randperm(N);
x(q(1:T)) = sign(randn(T,1));

% measurement matrix
disp('Creating measurment matrix...');
A = randn(K,N);
A = orth(A')';
disp('Done.');
   
% observations
y = A*x;

% initial guess = min energy
x0 = A'*y;

% solve the LP
tic
[m, n] = size(A);
f = [zeros(n, 1); ones(n, 1)];
Ai = [-eye(n), -eye(n); eye(n), -eye(n)];
bi = zeros(2*n, 1);
Aeq = [A, zeros(m, n)];
beq = y;
xp = linprog(f, Ai, bi, Aeq, beq);
xp = xp(1:n);
toc

% Quality of reconstruction, difference between x an xp using l2
norma_l2_x = norm(xp-x)

% signal-to-distortion ratio (SDR)
ratio = norm(x)/norm(x - xp)

figure;
subplot(2,1,1);
plot(x);
xlabel('sinal original');
subplot(2,1,2);
plot(xp);
xlabel('Reconstrucao usando linprog');



--
Juan Gabriel Colonna

1 comment:

lalitetaguchi said...

microtouch solo titanium - A beginner's miniaturized miniaturized
Learn how microtouch solo titanium works to maximize the power of your columbia titanium boots smartphone or gaming mens titanium rings device. mens titanium rings Learn how to mens titanium necklace install titanium blade microtouch