function partition = ProducePartition( a, b, f, cut )
% ProducePartition using the curvature of the signal f, it compute the knots of a 
% partition
%
% Usage:        partition = ProducePartition( a, b, f, cut );
%
% Inputs:  
%   a,b         the end points of the interval    
%   f           signal 
%   cut         sub-divided level of the partition.
%  
% Outputs: 
%   partition   the knots of the partition. The first entry is a and the last one is b

% See   http://www.ncrg.aston.ac.uk/Projects/HNLApprox/
%       http://www.nonlinear-approx.info/
L=max(size(f));
dist=(b-a)/L;
c=zeros(L,1);
for j=2:L-1
    c(j)=abs(((f(j+1)+f(j-1)-2*f(j))/dist^2)/(1+((f(j)-f(j-1))/dist)^2)^(3/2));
  %  fprint('%f ',c(j));
end

k=1;
partition(k)=a;
for j=3:L-2
    if c(j)>c(j-1) & c(j)>c(j+1)
        qi=partition(k);
        for t=1:cut
        k=k+1;
        partition(k)=((cut-t)*qi+t*(a+(j-1)*dist))/cut;
       end
        
    end
end

   qi=partition(k);
    for t=1:cut
        k=k+1;
        partition(k)=((cut-t)*qi+t*(b))/cut;
    end
    
% Zhiqiang Xu (2009)
