%% test
function [nmse_bp,nmse_omp,nmse_gamp] = test3method(M,SNR,noise)
if nargin<1
    M = 50;
    noise = 1;
    SNR =0;
end
N = 1600;
A = randn(M,N)+1j*randn(M,N);
K = 6;
x = zeros(N,1);
index = randperm(N,K);
x(index) =sqrt(1/2)* randn(K,1)+1j*rand(K,1);
% noise = 1;
% SNR = 10;
y = A*x;

if noise
    var_n = norm(y,'fro')^2/(M*10^(SNR/10));
    noi = sqrt(var_n/2)*(randn(M,1)+1j*rand(M,1));
    y = y+noi;
    bp_noi = norm(noi,'fro')
    x_bp = spg_bpdn(A,y,1.05*bp_noi);
%     x_omp = OMP_test(K,A,y);
    x_omp = OMP(y,A);
   
        %% gamp
%         gA= [real(A),-imag(A);imag(A), real(A)];
%             gy0 = [real(y);imag(y)];
%             [tr,tl] = size(gA(1,:)');
%         x_gamp = PCSBL_GAMP(gA,gy0,tr,tl,1,1,1e3,var(y)/1e0)
    optEM.robust_gamp = true;
    optEM.heavy_tailed = true;
    [x_gamp, EMfin] = EMBGAMP(y, A, optEM);

else
    bp_noi =0;
    x_bp = spg_bpdn(A,y,1.05*bp_noi);
%     x_omp = OMP_test(K,A,y);
    x_omp = OMP(y,A);
   
        %% gamp
%         gA= [real(A),-imag(A);imag(A), real(A)];
%             gy0 = [real(y);imag(y)];
%             [tr,tl] = size(gA(1,:)');
%         x_gamp = PCSBL_GAMP(gA,gy0,tr,tl,1,1,1e3,var(y)/1e6)
    optEM.robust_gamp = true;
    optEM.heavy_tailed = true;
    [x_gamp, EMfin] = EMBGAMP(y, A, optEM);
end

% x_gamp_n = (x_gamp(1:tr/2)+1j*x_gamp(tr/2+1:end)) ;

nmse_bp = norm(x_bp-x,'fro')^2/norm(x,'fro')^2
nmse_omp = norm(x_omp-x,'fro')^2/norm(x,'fro')^2
nmse_gamp = norm(x_gamp-x,'fro')^2/norm(x,'fro')^2
end
    
    
