SignalBase defines a basic API to inspect signals that are regularly sampled in time. It consists of the following functions.
sampletype
: a typeT <: Number
used to represent each sample, similar in purpose toeltype
, but some signals may define these two functions differently.nchannels
: the number of samples per frameframerate
: the number of frames per second, can be amissing
value.nframes
: the number of frames; this can be amissing
valueduration
: the duration in seconds of the signal (defaults tonframes(x) / framerate(x)
). This value can be amissing
value. This could be defined seperately fromnframes
if, for example, the framerate is unknown but the duration is known.
For example, one natural definition of an Array
, interpreted as a signal would be as follows.
sampletype(x::Array) = eltype(x)
nchannels(x::Array) = size(x,2)
framerate(x::Array) = missing
nframes(x::Array) = size(x,1)
Such a definition is provided by SignalOperators
.
This package also defines a set of utility functions for working with units relevant to signals via Unitful
: namely, radians, frames, seconds and Hertz. The frames
unit is newly defined here so that conversions between frames and units of time is convienient and unambiguous. The other three are already defined by Unitful
. The following functions are available.
inradians
: converts a quantity to radiansinframes
: converts a quantity to framesinseconds
: converts a quantity to secondsinHz
: converst a quantity to Hertz
These functions apply the following phillosophy: units can be useful as part of a public API, but they should be an optional feature. Therefore, if a value is passed with a given unit type (e.g. 1kHz
), use it. If the value has no unit specified, assume a default unit type: e.g. inHz(10.0) would assume that 10.0
is in units of Hertz. The returned value for all these functions are in the stated units, as a Float64
value.
The utility functions all properly handle missing
values.
To make use of the unit names themselves (e.g. s
for seconds) you can add them via SignalsBase.Units
. They are only exported in this sub-module to avoid pollutting the namespace with short unit names unless desired. The exported units are: kframes, frames, Hz, s, kHz, ms, dB, °, rad