dsp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Hour = time.Hour
	Day  = time.Hour * 24
	Week = Day * 7
)
View Source
var PeriodicityAmplitudeThreshold = 0.

Functions

func NewPrediction

func NewPrediction(realtimeProvider providers.RealTime, historyProvider providers.History, mc config.AlgorithmModelConfig) prediction.Interface

Types

type Estimator

type Estimator interface {
	GetEstimation(signal *Signal, cycleDuration time.Duration) *Signal
	String() string
}

func NewFFTEstimator

func NewFFTEstimator(minNumOfSpectrumItems, maxNumOfSpectrumItems int, highFrequencyThreshold, lowAmplitudeThreshold, marginFraction float64) Estimator

func NewMaxValueEstimator

func NewMaxValueEstimator(marginFraction float64) Estimator

type FrequencySpectrum

type FrequencySpectrum struct {
	Amplitudes  []float64
	Frequencies []float64
}

func (*FrequencySpectrum) Len

func (f *FrequencySpectrum) Len() int

func (*FrequencySpectrum) Less

func (f *FrequencySpectrum) Less(i, j int) bool

func (*FrequencySpectrum) Swap

func (f *FrequencySpectrum) Swap(i, j int)

type Signal

type Signal struct {
	// SampleRate is the sampling rate in hertz
	SampleRate float64
	// Samples store all samples
	Samples []float64
}

Signal represents a discrete signal.

func SamplesToSignal

func SamplesToSignal(samples []common.Sample, sampleInterval time.Duration) *Signal

func (*Signal) Denormalize

func (s *Signal) Denormalize(min, max float64) (*Signal, error)

Denormalize denormalizes the signal between min and max.

func (*Signal) Duration

func (s *Signal) Duration() float64

Duration returns the signal duration in seconds.

func (*Signal) Filter

func (s *Signal) Filter(threshold float64) *Signal

Filter filters out frequency components whose amplitudes are less than the threshold and returns a new signal

func (*Signal) Frequencies

func (s *Signal) Frequencies() []float64

Frequencies returns the signal frequency components in hertz in descending order.

func (*Signal) FrequencySpectrum

func (s *Signal) FrequencySpectrum() *FrequencySpectrum

FrequencySpectrum returns the frequency spectrum of the signal.

func (*Signal) IsPeriodic

func (s *Signal) IsPeriodic(cycleDuration time.Duration) bool

IsPeriodic checks whether the signal is periodic and its period is approximately equal to the given value

func (*Signal) Max

func (s *Signal) Max() float64

Max returns the maximum sample value.

func (*Signal) Min

func (s *Signal) Min() float64

Min returns the minimum sample value.

func (*Signal) Normalize

func (s *Signal) Normalize() (*Signal, error)

Normalize normalizes the signal between -1 and 1 and return a new signal instance.

func (*Signal) Num

func (s *Signal) Num() int

Num returns the number of samples in the signal.

func (*Signal) Plot

func (s *Signal) Plot(o ...charts.GlobalOpts) *charts.Line

func (*Signal) String

func (s *Signal) String() string

func (*Signal) Truncate

func (s *Signal) Truncate(d time.Duration) (*Signal, int)

Truncate truncates the signal to a length of multiple of d.

Jump to

Keyboard shortcuts

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