def average_channels(tdms_file, path_one, path_two, trim=False):
    """
    Average two channels from tdms_file given by their paths [group channel],
    trim result to the shorter of the two.
    """
    one = tdms_file.channel_data(*path_one)
    two = tdms_file.channel_data(*path_two)
    if len(one)==len(two):
        x = (one+two)/2
    elif len(one)>len(two) and trim:
        x = (one[0:len(two)]+two)/2
    elif len(one)<len(two) and trim:
        x = (two[0:len(one)]+one)/2            
    else: 
        raise ValueError("Channel length do not match.")
    return x