How to filter noisy distance sensor measurement

Sorry @whtcubie I’m not sure what you are talking about.
Better than what filter?
It would have been better if there is some data to compare with.

sorry,I am not very good at English.
I wonder if sonar usemedian filter or low pass filter is better.

It depends on how raw data looks like. If the data has noise only in high frequency range, LPE works better however if the noise is more like white noise, median filter may works better. So you definitely provide the raw data first.