The iBeacon ranging process (as available from CoreLocation) do not provide a smooth going distance of iPhone from an iBeacon instead it gives a too much fluctuating values. I also tried to use weighted average but it do not gives desired results. I come across the link that explained the use of Kalman Filter to remove noise from signals. I also came across a swift framework that has implemented the filter. My question is how to apply the kalman filter logic to get a smooth distance from iBeacon? I am currently using below code to calculate a distance but I do not have any idea how to apply a kalman filter over it.
func calculateNewDistance(txCalibratedPower: Int, rssi: Int) -> Double{
        if rssi == 0{
            return -1
        }
        let ratio = Double(exactly:rssi)!/Double(txCalibratedPower)
        if ratio < 1.0{
            return pow(10.0, ratio)
        }else{
            let accuracy = 0.89976 * pow(ratio, 7.7095) + 0.111
            return accuracy
        }
    }
Here txCalibratedPower is being passed as -74
 
    