function [q_new, t_new] = equalize_samples(q, t, period);

    index = 1;
    index_new = 1;

    old_length = length(q);

    q = [q q(old_length) q(old_length) q(old_length)];
    t = [t t(old_length)+0.001 t(old_length)+0.002 t(old_length)+0.003];

    t_cur = t(index);

    while index < old_length,

      incr = 1;
      index1 = index;
      index2 = index1 + 1;
      while ( ( abs(t(index2) - t(index1)) < 1e-6 )  )
        incr = incr+1;
        index2 = index2 + 1;
      end
	  if ( t_cur > t(index2) )
		index = index + incr;
		continue;
	  end

      index3 = index2 + 1;
      while ( abs(t(index3) - t(index2)) < 1e-6 )
        incr = incr+1;
        index3 = index3 + 1;
      end
      if ( index3 > old_length )
        break;
      end
      
      mat = [t(index1)^2 t(index1) 1; t(index2)^2 t(index2) 1; t(index3)^2 t(index3) 1];
      vec = [q(index1); q(index2); q(index3)];
      
      coeff = mat\vec;

      while t_cur < t(index2),
        t_new(index_new) = t_cur;
        q_new(index_new) = [t_cur^2 t_cur 1] * coeff;
		
        t_cur = t_cur + period;
        index_new = index_new + 1;
      end
      index = index + incr;
    end     
