def calculate_compensated_moment(moment_sample, x_sample, interp_gap, interp_reference, beta):
    """
    Calculates the compensated moment for a measurement of a sample.
    """
    return moment_sample - interp_reference(x_sample) + (beta * interp_gap(x_sample))