Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smooth the GPS data using Gaussian filter #3

Open
inode64 opened this issue Jun 2, 2023 · 0 comments
Open

smooth the GPS data using Gaussian filter #3

inode64 opened this issue Jun 2, 2023 · 0 comments

Comments

@inode64
Copy link
Owner

inode64 commented Jun 2, 2023

https://github.com/gonum/gonum

import "gonum.org/v1/gonum/stat/distuv"

type point struct {
	lat float64
	lng float64
}

func smoothGPSData(data []point, sigma float64) []point {
	smoothedData := make([]point, len(data))
	x := make([]float64, len(data))
	y := make([]float64, len(data))

	// Extract the latitude and longitude data into separate slices
	for i, p := range data {
		x[i], y[i] = p.lat, p.lng
	}

	// Create a Gaussian distribution with sigma as the standard deviation
	dist := distuv.Normal{
		Mu:    0,
		Sigma: sigma,
	}

	// Convolve the data with the Gaussian kernel
	for i := range x {
		for j := range y {
			kernel := dist.Prob(x[i] - x[j])
			smoothedData[i].lat += kernel * x[j]
			smoothedData[i].lng += kernel * y[j]
		}
	}

	return smoothedData
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant