|
压缩感知重构算法之压缩采样匹配追踪(CoSaMP)
具体可参考:
具体的MATLAB函数代码见附件:- clc,clear
- % -- Measurement matrix "A"
- N = 2^10;
- M = round(N/2);
- randn('state',239234);
- rand( 'state',239234);
- A = randn(M,N)/sqrt(M);
- % -- Sparse signal "x"
- K = round(M/5);
- T = randperm(N);
- T = T(1:K);
- x = zeros(N,1);
- x(T)= randn(K,1);
- %% Add some noise:
- NOISE_LEVEL = 3; % choose
- b = A*x;
- randn('state',94350);
- switch NOISE_LEVEL
- case 1
- sigma = 0; % noiseless
- disp('-------- Noiseless setting ----------');
- case 2
- sigma = .3*norm(b)/sqrt(M); % noisy
- disp('-------- Noisy setting --------------');
- case 3
- sigma = .9*norm(b)/sqrt(M); % extremely noisy
- disp('-------- Very noisy setting ---------');
- end
- z = sigma*randn(M,1);
- b = b + z;
- opts = [];
- opts.maxiter = 50;
- opts.tol = 1e-8;
- opts.HSS = true;
- opts.two_solves = true; % this can help, but no longer always works "perfectly" on noiseless data
- opts.printEvery = 10;
- % K_target = round(length(b)/3)-1; opts.normTol = 2.0;
- K_target = 50; % When extremely noisy, this is best; when no noise, this is sub-optimal
- if sigma == 0
- % K_target = 100; % This doesn't work "perfectly" but is OK
- % K_target = 102; % This works "perfectly" with noiseless data
- K_target = 150; % Slower, but works "perfectly" with noiseless data
- end
- % opts.addK = 2*K_target; % default
- opts.addK = K_target; % this seems to work a bit better
- % opts.addK = 5; % make this smaller and CoSaMP behaves more like OMP
- % (and does better for the correlated measurement matrix)
- % opts.support_tol = 1e-2;
- fprintf('CoSaMP, -------------------------------\n\n');
- [xk] = CoSaMP( A, b, K_target, [], opts);
- fprintf('Error is %.2e\t\n\n', norm(xk-x)/norm(x));
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|