function [f_vals, x] = reconstLegendre( coeffs, max_deg, num_samples)
%
% [f_vals, x] = reconstLegendre( coeffs, max_deg, num_samples)
%

  defval( 'max_deg', numel(coeffs)-1);
  defval( 'num_samples', 1000);

  % x-axis sample values for signal
  x = [-1.0 : (2/(num_samples-1)) : 1.0];
  
  % memory for function values
  f_vals = zeros( size(x));
  
  for( deg = 0 : max_deg)
    
    % evaluate Legendre polynomial (and extract the one relevant for us)
    legendre_vals = legendre( deg, x, 'norm');
    if( 0 == deg) 
      legendre_vals = legendre_vals(:,1);
    else 
      legendre_vals = legendre_vals(1,:);
    end
  
    % add contribution of current band
    f_vals = f_vals + (coeffs(deg+1) * legendre_vals);
    
  end

end