Documentation ¶
Overview ¶
Package wavegen is used for generating synthetic test data for the Dropbear LSTM project.
Index ¶
- type Sample
- type SampleList
- type Signal
- func (s *Signal) AverageSampleRate() float64
- func (s *Signal) Duration() float64
- func (s *Signal) Index(i int) (Sample, error)
- func (s *Signal) Interpolate(times ...float64) []Sample
- func (s *Signal) Len() int
- func (s *Signal) MustIndex(i int) Sample
- func (s *Signal) NearestIndex(time float64, overshoot bool) int
- func (s *Signal) Size() int
- func (s *Signal) Summarize() (string, error)
- func (s *Signal) ValidateIndex(i int) error
- func (s *Signal) XY(i int) (float64, float64)
- type WaveFile
- type WaveParameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sample ¶
type Sample struct { // The time component of the sample T float64 // The value component of the sample S float64 }
Sample represents a single sample from a Signal
type SampleList ¶
type SampleList []Sample
func (SampleList) ToSignal ¶
func (l SampleList) ToSignal() *Signal
ToSignal converts a list of samaples to a Signal object, and sets the sample rate thereof to their average sample rate.
type Signal ¶
type Signal struct { // signal values S []float64 `json:"samples"` T []float64 `json:"times"` // sample rate in Hz, note that this is set by the caller, this library // cannot guarantee the accuracy of this value SampleRate float64 }
Signal represents a time-series signal
When generating or modifying a signal, you must guarantee that the T and S values are sorted by T (e.g. earlier points in time have lower indices), and that T ans S are the same size.
func (*Signal) AverageSampleRate ¶
AverageSampleRate calculates the average sample rate in Hz of the signal. This can be useful when dealing with real signals, rather than those generated using wavegen.
func (*Signal) Interpolate ¶
Interpolate can be used to perform linear interpolation. It will compute a separate linear interpolation for each point in times, and return an appropriate sample for each.
func (*Signal) MustIndex ¶
MustIndex works identically to Index(), but calls panic() if an error occurs
func (*Signal) NearestIndex ¶
NearestIndex will return the index within a signal which has a time value as close as possible to the specified time argument. It will return an index with a greater or equal value if overshoot is true, and a lesser or equal value if overshoot is false. It will return 0 if the time value is before the beginning of the signal, and s.Size()-1 if the time value is after the end of the signal.
Note that time includes the offset, so time=0 when the offset is 1 second will return 0, since it is before the beginning of the signal data.
func (*Signal) ValidateIndex ¶
ValidateIndex ensures that the specified index can be retrieved from the signal, and generates an error if not.
type WaveFile ¶
type WaveFile struct { // Version should be the version specifier, currently 0. Version int // Parameters represents the WaveParameters. Parameters *WaveParameters `json:",omitempty"` // Signal represents the wave data. Signal *Signal `json:",omitempty"` }
WaveFile represents all of the data that could be encoded in a WaveGen JSON file.
type WaveParameters ¶
type WaveParameters struct { // SampleRate is the sample rate at which the wave should be generated, // in Hz SampleRate float64 // Offset is the time at which samples should begin being collected, in // seconds Offset float64 // Duration is the number of seconds of samples that should be generated Duration float64 // Frequencies is the list of frequencies of Sin wave that should be // generated Frequencies []float64 // Phases is the list of phases of the Sin waves that should be // generated Phases []float64 // Amplitudes is the list of amplitudes of Sin that should be generated Amplitudes []float64 // Noises stores a list of noise functions which are applied on a // per-signal basis. if this field is left empty, then no noise will // be generated for the given signal. These noise functions are // understood: // // * "pseudo" (rand.Float64) // * "none" (no noise) // * "" (no noise) Noises []string // NoiseMagnitues is a list of coefficients to the given noise function // for a particular signal. If empty, it is assumed that all // magnitudes are 1.0. NoiseMagnitudes []float64 // GlobalNoise accepts the same values as Noises, but are applied // globally rather than to a specific signal. GlobalNoise string // GlobalNoiseMagnitude works similarly to NoiseMagnitudes, but applies // to the global noise. GlobalNoiseMagnitude float64 }
WaveParameters is used to store the parameters that generate a particular wave. See GenerateSyntheticData().
func (*WaveParameters) GenerateSyntheticData ¶
func (w *WaveParameters) GenerateSyntheticData() (*Signal, error)
GenerateSyntheticData generates a signal which is a composition of several Sin functions of the given frequencies, phases, and amplitudes, with noise optionally applied to each signal, and optionally applied to the data overall.
func (*WaveParameters) Noise ¶
func (w *WaveParameters) Noise(index int) (float64, error)
Noise generates a randomized noise value for the index-th component of the wave parameter. An index of -1 indicates that the global noise should be generated instead.
func (*WaveParameters) Summarize ¶
func (w *WaveParameters) Summarize() (string, error)
func (*WaveParameters) ValidateParameters ¶
func (w *WaveParameters) ValidateParameters() error
ValidateParameters will ensure that the parameters are valid.
If the noises or noise magnitudes are empty, then they will be filled to an appropriate length with default values.