Last active
September 7, 2015 08:04
-
-
Save tobie/592796801977029e35c9 to your computer and use it in GitHub Desktop.
Sensor sample frequency
This file contains 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
// Trying to find the formula to determine the frequency | |
// at which to sample GPS coordinates of a moving vehicle | |
// in order to have the maximum precision but not to store | |
// more data than necessary. | |
let precision = 1; // The precision of the GPS in meters | |
let max_speed = 180 / 3.6 // 180km/h converted to m/s = 50m/s | |
let max_frequency = max_speed / precision; | |
// Nyquist–Shannon sampling theorem[1] tells us a | |
// sufficient sample-rate is 2B samples/second, or anything larger, thus: | |
let min_sample_rate = 2 * max_frequency; // 100Hz | |
// As a second step, considering this data is for display | |
// on a digital map, figure out how you can further lower | |
// the requirements given screen size, pixel density and | |
// map zoom factor. | |
// From Bing Map Tiles System[2] we learn that | |
// the following forumla can be applied to get | |
// the map resolution (in px/m). | |
let resolution = (latitude, zoomLevel) => { | |
let PI = Math.PI; | |
let EARTH_CIRC = 6378137; | |
return (Math.cos(latitude * PI/180) * 2 * PI * EARTH_CIRC) / (256 * Math.pow(2, zoomLevel)); | |
} | |
// This gives a ~0.5m/px resolution at my latitude and a zoom level of 18, | |
// which is actually more precise that a GPS resolution of 1m. | |
// We thus can't reduce the sample rate at that zoom level. | |
// Should we offer a much higher view, however, | |
// e.g. a zoom level of 10, which gives a resolution of ~150m/px | |
// then we could lower our sample rate accordingly: | |
let min_sample_rate_at_zoom_level_10 = 2 * (max_speed / 150); // 0.67Hz | |
// so just a little under 2 samples per second. | |
// So factoring all the variables: | |
let minFrequency = (maxSpeed /* m/s */, latitude, zoomLevel) { | |
let PI = Math.PI; | |
let EARTH_CIRC = 6378137; | |
let GPS_PRECISION = 1; // 1m it's proabbly worse, actually. | |
let resolution = (Math.cos(latitude * PI/180) * 2 * PI * EARTH_CIRC) / (256 * Math.pow(2, zoomLevel)); | |
let precision = Math.max(GPS_PRECISION, resolution); | |
return 2 * (maxSpeed / precision); | |
} | |
// Still TODO: include pixel density in the equation. | |
// [1] https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem | |
// [2] https://msdn.microsoft.com/en-us/library/bb259689.aspx | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/cc @rwaldron (does the above reasoning make sense?)