OMP.m 655 B

1234567891011121314151617181920212223242526
  1. function [ x ] = OMP( y , D , k )
  2. residual = y;
  3. Atoms_sel = zeros(k,1);
  4. D_select = zeros(size(D,1),k);
  5. x_OMP = zeros(k,1);
  6. for iter = 1 : k
  7. [ ~ , idx_max ] = max(abs(residual'*D));
  8. Atoms_sel(iter) = idx_max;
  9. D_select(:,iter) = D(:,Atoms_sel(iter));
  10. for j = 1 : iter-1
  11. D_select(:,iter) = D_select(:,iter)-real(D_select(:,iter)'*D_select(:,j))*D_select(:,j);
  12. end
  13. D_select(:,iter) = D_select(:,iter)/norm(D_select(:,iter));
  14. x_OMP(iter) = real(D_select(:,iter)'*residual);
  15. residual = residual-D_select(:,iter)*x_OMP(iter);
  16. end
  17. x = zeros(size(D,2),1);
  18. x(Atoms_sel) = real(D(:,Atoms_sel)\y);