function coeffs = projCharacteristic( dim, f, num_samples)
%
% coeffs = projCharacteristic( dim, f)
%
% Project the function f into a uniform characteristic basis of dimension 
% dim. 

  defval( 'num_samples', 100000);

  % employ a normalized characteristic basis
  len_basis = 2.0 / dim;
  h = (1.0 / sqrt(len_basis));
    
  % memory for basis function coefficients
  coeffs = zeros( dim, 1);

  % generate random numbers for Monte Carlo integration
  num_samples_fct = ceil(num_samples/dim);
  x = (rand( [num_samples_fct, 1]) * len_basis) - 1.0;
  
  % do for all Legendre polynomials
  for( i = 1 : dim)

    % evaluate signal
    f_vals = f(x);
    c_vals = repmat( h, size( f_vals));
    
    % approximate current coefficient
    coeffs(i) = (len_basis / num_samples_fct) * dot( c_vals, f_vals);
  
    % move x values ot the right
    x = x + len_basis;
    
  end


end