# Calculating Median Speed with Spotty Data

I have a situation where I need to calculate the speed of a vehicle for a given time period. The data I'm working with is very spotty in the temporal dimension— we might have 5-10 speeds recorded within seconds of each other, but other speeds in the set might be many seconds or minutes apart. The speeds can sometimes be wildly inaccurate which is why we're using median instead of mean.

What we're noticing is this: because of the spottiness of the data, clusters of closely recorded points tend to skew the results of a median calculation because they take up a large amount of the sorted set from a count standpoint, but only represent a relatively small amount from a temporal standpoint.

We've considered interpolating the points (using a linear function) between large gaps in our measurements in order to smooth it out.

Question: is there a better way to solve this problem than by interpolating missing points? Is there a better option than using median (assuming we'll have outliers)?

• How dynamic do you expect your speed to be? Do you have better information on your acceleration? (Speed is a simple function of acceleration and time.) Could you pull a sample of your data based upon defined time intervals? Commented Apr 10, 2017 at 18:37
• Unfortunately that's the problem— I can't get the data for a set time interval. I'm working with data that comes from a GPS that has spotty connectivity. There will be moments where it has a great connection and plenty of regularly spaced points, but other times it might have a bad connection and not update itself for long periods of time. Commented Apr 11, 2017 at 16:48
• I think that this problem may have many solutions. Perhaps the best should be to use the Discrete Fourier transform. Commented Jun 29, 2019 at 7:09
• I answered a similar question at stats.stackexchange.com/questions/504734/… Commented Jul 14, 2022 at 20:25
• "The data I'm working with is very spotty in the temporal dimension" can you tell more about the data gathering process. Why is it spotty? If it correlates with the speed, e.g in tunnel where a vehicle has to drive more slowly there is no connection, then you have a problem with sample bias. Or can we assume that the sampling is random? Commented Apr 23, 2023 at 19:37