title: iOS Swift: Calculate distance from RSSI
body: <p>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 <a href="https://www.wouterbulten.nl/blog/tech/kalman-filters-explained-removing-noise-from-rssi-signals/" rel="nofollow noreferrer">link</a> that explained the use of Kalman Filter to remove noise from signals. I also came across a <a href="https://github.com/wearereasonablepeople/KalmanFilter" rel="nofollow noreferrer">swift framework</a> 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.</p>
  
  <pre><code>func calculateNewDistance(txCalibratedPower: Int, rssi: Int) -&gt; Double{
          if rssi == 0{
              return -1
          }
          let ratio = Double(exactly:rssi)!/Double(txCalibratedPower)
          if ratio &lt; 1.0{
              return pow(10.0, ratio)
          }else{
              let accuracy = 0.89976 * pow(ratio, 7.7095) + 0.111
              return accuracy
          }
  
      }
  </code></pre>
  
  <p>Here txCalibratedPower is being passed as -74</p>