Last active
June 3, 2019 12:50
-
-
Save trevphil/6b1371b9b9ba534100d4162a4d29ac20 to your computer and use it in GitHub Desktop.
True location to noisy location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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