function [x,res] = omp(b,A,k)
% compute k-sparse approximation to b with matrix A using Matching pursuit
[m,N] = size(A);
x = zeros(N,1);
res = b;
support = [];
A_get=zeros(m,k);
for i=1:k
corr = (A')*res;
[c,n] = max(abs(corr));
support(end+1) = n;
A_get(:,i)=A(:,n);
A(:,n)=zeros(m,1);
%x(support) = pinv(A(:,support))*b
x(support)=(A_get(:,1:i)'*A_get(:,1:i))^(-1)*A_get(:,1:i)'*b;
%res = res - A(:,support)*x(support)
res=b-A_get(:,1:i)*x(support);%相乘为向量的正交投影
end