function [Ans,error]=OMP(Phi,y,K)
[N P]=size(Phi);
Ans=zeros(P,1);
residual=y;
Phit=[];
index=[];
for idx=1:K
tmp=Phi'*residual;
[val loc]=max(abs(tmp));
val=tmp(loc);
index=[index loc];
Phit=[Phit Phi(:,loc)];
Ans_est=pinv(Phit)*y;
residual=y-Phit*Ans_est;
end
Ans(index)=Ans_est;
error=sum(abs(residual));
end