function theta_hat = OMP_test(K,A,y)
% input: K ---sparsity of theta (the orginal signal) A-----sensing
% matrix(m*n---->K<<m<<n)  y----measurements vector n*1
% y=A*theta -->theta_hat
r=y;
[M,N]=size(A);
theta_hat=zeros(N,1);
Gamma=zeros(1,K);
% A_Gamma=zeros(M,K);
A_Gamma=[];
for t=1:K
    [~,lamda]=max(abs(A'*r));%lamba is index
    Gamma(t)= lamda;
    A_Gamma=[A_Gamma A(:,lamda)];
    theta_h=(A_Gamma'*A_Gamma)\A_Gamma'*y;
    r=y-A_Gamma*theta_h;
%     A_Gamma(:,t)=A(:,lamda);
%     A(:,lamda)=zeros(M,1);
%     A(:,lamda)=[];
%     A_Gamma(:,t)=A(:,lamda);
%     theta_h=(A_Gamma(:,1:t)'*A_Gamma(:,1:t))\A_Gamma(:,1:t)'*y;
%      r=y-A_Gamma(:,1:t)*theta_h;
end
theta_hat(Gamma)=theta_h;
end