function [ fv, Vnew, Di, beta, c, U, Q ] = OBOMP( f, V, WC, err, No, opt, ind )
% OBOMP Oblique Optimized Matching Pursuit
%
% Constructs an atomic decomposition which gives the oblique projection of a signal onto a
% subspace of the span of V along span of WC. 
%
% It first generates orthogonal projections onto the orthogonal complement ofthe span of
% WC and then find the atomic decomposition of the projected signal by the OOMP method.
%
% For an example of how to use OBOMP to separate signal components run the code Exa_OBOMP 
%
% Usage:    [ fv ] = OBOMP( f, V, WC );
%           [ fv, Vnew, Di, beta, c, U, Q ] = OBOMP( f, V, WC, err, No, opt, ind );
%
% Inputs:
%   f       signal to be projected
%   V       dictionary for the space to project onto
%   WC      dictionary spanning the space to project along
%   err     error of each point of f (vector) or tolerance for the error's norm (scalar) 
%   No      (optional) maximal number of atoms to choose, if the number of chosen atoms
%           equals to No, the routine will stop (default No=size(V,2)) 
%   ind     (optional) indices determining  the initial subspace
%   opt     (optional) chose the method for computing the orthogonal projector with
%           OrthProj (default opt=2 with tolerance for linear independence 1e-7)  
%
% Outputs:
%   Vnew    the dictionary V rearranged according to the selection process Vnew(:,1:k)
%           contains the atoms chosen into the atomic decomposition  
%   Di      indices of atoms in Vnew written w.r.t the original V
%   U       Dictionary for the orthogonal complement of WC (U(:,1:k)) is a basis
%           bi-orthogonal to beta)  
%   Q       the first k columns Q(:,1:k) gives an orthonormal basis for the span of
%           U(:,1:k)
%   beta    'k' biorthogonal vectors to new  V(:,1:k) and U(:,1:k) (in span of U(:,1:k)) 
%   c       'k' coefficients of the atomic decomposition for the oblique projection 
%   fv      oblique projection of f onto  new  V(:,1:k) along WC, i.e fv=Vnew(:,1:K)*c' 
%
% References
%   [1] L. Rebollo-Neira, "Oblique Matching Pursuit", IEEE Signal Processing Letters,
%   14,10, 703-707 (2007). 
%   [2] L. Rebollo-Neira, "Measurements design and phenomena discrimination", J. Phys. A:
%   Math. Theor. 42 (2009).  
%
% See also  OBOMPKSwaps OOMP OOMPKSwaps


% See   http://www.ncrg.aston.ac.uk/Projects/HNLApprox/
%       http://www.nonlinear-approx.info/


name='OBOMP';  %name of the routine
%get inputs and initialize defaults
[L,N]=size(V);
beta=[];
if nargin<7 ind=[];end
if (nargin<6) | (isempty(opt)==1); opt=2; end
if (nargin<5) | (isempty(No)==1); No=N;end
if (nargin<4) | (isempty(err)==1); err=1e-10*norm(f);end
%
%============================================
%construct the orthogonal projector onto WC
%============================================
[O,PWC]=OrthProj(WC,opt);
%============================================
%projects the signal f and the subspaces V
%============================================
U=V-PWC*V;
fw=f'-PWC*f'; %this can be changed to tune the tolerance for the error norm
%errw=(err'-PWC*err');
if max(size(err))==1 tol=err
  else tol=norm(err);
end
%========================================================================
%find the sparse representation of fw with dictionary U using OOMP method
%========================================================================
[SU,Di,beta,c,Q]=OOMP(fw',U,tol,No,ind);
di=size(beta,2);
U=SU;
Vnew=V(:,Di);
fv=Vnew(:,1:di)*c';

%Laura Rebollo-Neira 2008 (Last modification june 2009)
