Skip to content

Instantly share code, notes, and snippets.

@trevphil
Last active June 3, 2019 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevphil/6b1371b9b9ba534100d4162a4d29ac20 to your computer and use it in GitHub Desktop.
Save trevphil/6b1371b9b9ba534100d4162a4d29ac20 to your computer and use it in GitHub Desktop.
True location to noisy location
func addNoise(to trueLocation: CLLocation) -> CLLocation {
let distanceWiggle = sampleNormalDist(withMean: 0, std: 0.952)
let xContribution = rng.nextUniform()
let xoff = distanceWiggle * Double(xContribution)
let yoff = distanceWiggle * sqrt(1 - pow(Double(xContribution), 2))
let newCoord = trueLocation.coordinate.offsetBy(xMeters: xoff, yMeters: yoff)
let newHacc = sampleNormalDist(withMean: 7.179, std: 1.682)
let newVacc = sampleNormalDist(withMean: 3.643, std: 0.300)
let timeWiggle = sampleNormalDist(withMean: 1.00, std: 0.131)
let newTime = trueLocation.timestamp.addingTimeInterval(timeWiggle)
return CLLocation(coordinate: newCoord,
altitude: trueLocation.altitude,
horizontalAccuracy: max(0, newHacc),
verticalAccuracy: max(0, newVacc),
course: trueLocation.course,
speed: trueLocation.speed,
timestamp: newTime)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment