Documentation
¶
Overview ¶
Package time provides time-domain statistical metrics.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CrestFactor ¶
CrestFactor returns the crest factor (peak / RMS) of the signal. Returns 0 if RMS is zero.
func Moments ¶
Moments returns the mean, population variance, skewness, and excess kurtosis of the signal using Welford's online algorithm for numerical stability.
func ZeroCrossings ¶
ZeroCrossings returns the number of zero crossings in the signal. A crossing is counted when consecutive samples have opposite signs.
Types ¶
type Stats ¶
type Stats struct {
Length int
DC float64 // mean
DC_dB float64
RMS float64
RMS_dB float64
Max float64
MaxPos int
Min float64
MinPos int
Peak float64 // max(|max|, |min|)
Peak_dB float64
Range float64 // max - min
Range_dB float64
CrestFactor float64 // peak / RMS (linear)
CrestFactor_dB float64
Energy float64 // sum of squares
Power float64 // energy / length
ZeroCrossings int
Variance float64
Skewness float64
Kurtosis float64
}
Stats holds time-domain signal statistics.
func Calculate ¶
Calculate computes all time-domain statistics in a single pass using Welford's online algorithm for numerical stability on higher-order moments.
Example ¶
package main
import (
"fmt"
timestats "github.com/cwbudde/algo-dsp/stats/time"
)
func main() {
s := timestats.Calculate([]float64{1, -1, 1, -1})
fmt.Printf("rms=%.1f zc=%d\n", s.RMS, s.ZeroCrossings)
}
Output: rms=1.0 zc=3
type StreamingStats ¶
type StreamingStats struct {
// contains filtered or unexported fields
}
StreamingStats accumulates time-domain statistics incrementally across multiple blocks of samples. It processes each sample individually to guarantee bit-for-bit identical results with Calculate.
Example ¶
package main
import (
"fmt"
timestats "github.com/cwbudde/algo-dsp/stats/time"
)
func main() {
s := timestats.NewStreamingStats()
s.Update([]float64{1, -1})
s.Update([]float64{1, -1})
m := s.Result()
fmt.Printf("len=%d dc=%.1f\n", m.Length, m.DC)
}
Output: len=4 dc=0.0
func NewStreamingStats ¶
func NewStreamingStats() *StreamingStats
NewStreamingStats creates a new StreamingStats accumulator.
func (*StreamingStats) Reset ¶
func (s *StreamingStats) Reset()
Reset clears all accumulated data, allowing the StreamingStats to be reused.
func (*StreamingStats) Result ¶
func (s *StreamingStats) Result() Stats
Result computes the final statistics from accumulated data.
func (*StreamingStats) Update ¶
func (s *StreamingStats) Update(samples []float64)
Update adds a block of samples to the running statistics.