I am trying to smooth out a serie of values that represents tempo values, depicted in blue.
The data comes from a tempo detection algorithm that as you might have guessed is not the best in town, the expected tempo is 126 (depicted in red) but the algorithm is fooled by double beats hence the erratic values.
I've tried to use a moving average (depicted in green), while the average value stabilizes over time it tends to go up to about 170.
Do you know whether there's a magic formula that would allow to closely follow the red line ?

EDIT : using median
