detector

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 2 Imported by: 7 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package detector implements vibration detection, orientation tracking (Mahony AHRS), and experimental heartbeat (BCG) detection from IMU data.

Index

Constants

View Source
const SampleRate = 100

SampleRate is the expected input sample rate in Hz.

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

type Detector struct {
	SampleCount int
	FS          int

	// Latest raw values
	LatestRaw [3]float64
	LatestMag float64

	// Waveform history
	Waveform    *RingFloat
	WaveformXYZ *RingVec3

	STALTAActive [3]bool
	STALTALatest [3]float64
	STALTARings  [3]*RingFloat

	CUSUMVal float64

	Kurtosis float64

	Crest    float64
	RMS      float64
	Peak     float64
	MADSigma float64

	// RMS trend
	RMSTrend *RingFloat

	// Events
	Events []Event

	// Gyro latest
	GyroLatest [3]float64

	// Mahony AHRS quaternion
	Q [4]float64 // w, x, y, z

	HRBPM   float64
	HRConf  float64
	HRValid bool

	// Periodicity
	Period      float64
	PeriodFreq  float64
	PeriodCV    float64
	PeriodSTD   float64
	PeriodValid bool
	ACorrRing   []float64
	// contains filtered or unexported fields
}

Detector processes accelerometer and gyroscope data to detect vibrations, compute orientation, and estimate heartbeat.

func New

func New() *Detector

New creates a new Detector with default parameters.

func (*Detector) DetectHeartbeat

func (d *Detector) DetectHeartbeat()

DetectHeartbeat uses autocorrelation of the bandpassed signal to estimate BPM.

func (*Detector) DetectPeriodicity

func (d *Detector) DetectPeriodicity()

DetectPeriodicity computes autocorrelation to find periodic vibration patterns.

func (*Detector) GetOrientation

func (d *Detector) GetOrientation() Orientation

GetOrientation returns the current Euler angles from the AHRS quaternion.

func (*Detector) Process

func (d *Detector) Process(ax, ay, az, tNow float64) float64

Process ingests one accelerometer sample and returns the dynamic magnitude.

func (*Detector) ProcessGyro

func (d *Detector) ProcessGyro(gx, gy, gz float64)

ProcessGyro updates the latest gyroscope reading (deg/s).

func (*Detector) STALTAOn

func (d *Detector) STALTAOn(i int) float64

STALTAOn returns the STA/LTA on-threshold for the given timescale index.

type Event

type Event struct {
	Time      time.Time
	Severity  string
	Symbol    string
	Label     string
	Amplitude float64
	Sources   []string
	Bands     []string
}

Event represents a detected vibration event.

type Orientation

type Orientation struct {
	Roll, Pitch, Yaw float64 // degrees
}

Orientation holds Euler angles derived from quaternion AHRS.

type RingFloat

type RingFloat struct {
	// contains filtered or unexported fields
}

RingFloat is a fixed-capacity ring buffer for float64 values.

func NewRingFloat

func NewRingFloat(cap int) *RingFloat

NewRingFloat creates a RingFloat with the given capacity.

func (*RingFloat) Len

func (r *RingFloat) Len() int

Len returns the number of elements in the buffer.

func (*RingFloat) Push

func (r *RingFloat) Push(v float64)

Push adds a value to the ring buffer.

func (*RingFloat) Slice

func (r *RingFloat) Slice() []float64

Slice returns the buffer contents in insertion order.

type RingVec3

type RingVec3 struct {
	// contains filtered or unexported fields
}

RingVec3 is a fixed-capacity ring buffer for Vec3 values.

func NewRingVec3

func NewRingVec3(cap int) *RingVec3

NewRingVec3 creates a RingVec3 with the given capacity.

func (*RingVec3) Len

func (r *RingVec3) Len() int

Len returns the number of elements.

func (*RingVec3) Push3

func (r *RingVec3) Push3(x, y, z float64)

Push3 adds XYZ values to the ring.

func (*RingVec3) Slice

func (r *RingVec3) Slice() []Vec3

Slice returns the buffer contents in insertion order.

type Vec3

type Vec3 struct {
	X, Y, Z float64
}

Vec3 holds a 3D vector.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL