implement and test function for calculating moving averages for centroids