19 March 2013

Compressive sensing example with Matlab

Descargar http://ml-collection.googlecode.com/svn-history/r18/trunk/l1-l2/l1magic-1.11.zip

Crear un .m en matlab con el código siguiente:

clear all
close all
clc

% put key subdirectories in path if not already there
path(path, '/home/algoritmos/l1magic-1.11/l1magic/Optimization');
path(path, '/home/algoritmos/l1magic-1.11/l1magic/Data');

% To reproduce the experiment
load RandomStates
rand('state', rand_state);
randn('state', randn_state);

% 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.');

y = A*x ;

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

% solve the LP
tic
xp = l1eq_pd(x0, A, [], y, 1e-3);
toc

nor = norm(xp-x)

subplot(4,1,1)
plot(x);
xlabel('sinal original');
subplot(4,1,2)
plot(y);
xlabel('amostras do sinal'); 
subplot(4,1,3)
plot(x0)
xlabel('estimacao inicial');
subplot(4,1,4)
plot(xp)
xlabel('sinal reconstruida'); 

Resultado   norm(xp-x) = 8.9647e-05
 

No comments: