function [offset] = NumCellsOffset(number_cells_moving,number_cells_target)

num_time_points = 20;

number_cells_moving_cut = number_cells_moving(1:20);
number_cells_target_cut = number_cells_target(1:20);

x = 1:num_time_points;
x_prime = 1:.2:num_time_points;

num_time_points_expanded = (num_time_points-1)*5 + 1;

number_cells_moving_oversampled = interp1(x,number_cells_moving_cut,x_prime,'pchip');
number_cells_target_oversampled = interp1(x,number_cells_target_cut,x_prime,'pchip');

clear('error_a');

for a = (-num_time_points_expanded)+1:num_time_points_expanded - 1
    
    clear value
    value = 0;
    clear number_cells_moving_offset
    number_cells_moving_offset = 0;
        
    if a<=0
        for i = 1:num_time_points_expanded-abs(a)
            number_cells_moving_offset(i) = number_cells_moving_oversampled(i-a);
            value(i) = (number_cells_target_oversampled(i) - number_cells_moving_offset(i))^2;
        end
    elseif a>0
        for i = 1:num_time_points_expanded-abs(a)
            number_cells_moving_offset(i+a) = number_cells_moving_oversampled(i);
            value(i) = (number_cells_target_oversampled(i+a) - number_cells_moving_offset(i+a))^2;
        end
    end

    error_a(a-ceil(-num_time_points_expanded)) = sum(value) / size(num_time_points_expanded - abs(a),2);
end

[Y,I] = min(error_a)

error_a

offset = I - num_time_points_expanded;