Skip to content

smooth the GPS data using Gaussian filter #3

@inode64

Description

@inode64

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions