more refactoring of avg_time_frequency to extract a helper function