Documentation ¶
Overview ¶
Package gdsp provides the types and functions necessary to process digital signals.
Index ¶
- func ComplexRI(r int) complex128
- func Filter(b Vector, a Vector, x Vector, z Vector) (Vector, Vector)
- func FilterC(b VectorComplex, a VectorComplex, x VectorComplex, z VectorComplex) (VectorComplex, VectorComplex)
- func FrequencyExtrapolate(input Vector, count int, windowLength int, windowType WindowType) (Vector, Vector)
- func IsClose(a float64, b float64, tolerance float64) bool
- func IsCloseC(a complex128, b complex128, tolerance float64) bool
- func Max(v Vector) float64
- func MaxI(n ...int) int
- func MaxImag(v VectorComplex) float64
- func MaxReal(v VectorComplex) float64
- func Mean(v Vector) float64
- func Median(v Vector) float64
- func Min(v Vector) float64
- func MinI(n ...int) int
- func MinImag(v VectorComplex) float64
- func MinReal(v VectorComplex) float64
- func StdDev(v Vector) float64
- func VESum(v Vector) float64
- func VESumC(v VectorComplex) complex128
- func VMulESum(u Vector, v Vector) float64
- func VMulESumC(u VectorComplex, v VectorComplex) complex128
- func VSumSq(v Vector) float64
- func VSumSqC(v VectorComplex) complex128
- type Matrix
- type MatrixComplex
- type Vector
- func ACorr(u Vector) Vector
- func Arburg(x Vector, p int) (Vector, float64)
- func Conv(u Vector, v Vector) Vector
- func Extrapolate(input Vector, n int) Vector
- func Filtic(b Vector, a Vector, y Vector, x Vector) Vector
- func GaussianLowpass(input Vector, cutoff float64) Vector
- func IIR(input Vector, response float64) Vector
- func Interpolate(input Vector, upsampleMultiple int) Vector
- func InverseSpectrogram(spectrogram MatrixComplex, windowType WindowType) Vector
- func MakeVector(repeating float64, count int) Vector
- func MakeVectorFromArray(input []float64) Vector
- func Normalize(v Vector) Vector
- func NormalizeStrict(v Vector) (Vector, []float64)
- func VAbs(v Vector) Vector
- func VAdd(u Vector, v Vector) Vector
- func VMagC(v VectorComplex) Vector
- func VMulE(u Vector, v Vector) Vector
- func VNeg(v Vector) Vector
- func VSAdd(v Vector, s float64) Vector
- func VSDiv(v Vector, s float64) Vector
- func VSMul(v Vector, s float64) Vector
- func VSSub(v Vector, s float64) Vector
- func VSub(u Vector, v Vector) Vector
- func XCorr(u Vector, v Vector) Vector
- func (v Vector) Copy() Vector
- func (v Vector) IsCloseToVector(u Vector, tolerance float64) bool
- func (v Vector) IsZero() bool
- func (v Vector) Padded(leadingValue float64, leadingCount int, trailingValue float64, ...) Vector
- func (v Vector) PaddedLeading(leadingValue float64, leadingCount int) Vector
- func (v Vector) PaddedTrailing(trailingValue float64, trailingCount int) Vector
- func (v Vector) Reverse(start int, stop int) Vector
- func (v Vector) Reversed() Vector
- func (v Vector) SubVector(start int, stop int) Vector
- func (v Vector) ToComplex() VectorComplex
- type VectorComplex
- func ACorrC(u VectorComplex) VectorComplex
- func ArburgC(x VectorComplex, p int) (VectorComplex, complex128)
- func ConvC(u VectorComplex, v VectorComplex) VectorComplex
- func DFT(input VectorComplex, forward bool) VectorComplex
- func ExtrapolateC(input VectorComplex, count int) VectorComplex
- func FFT(input VectorComplex) VectorComplex
- func FilticC(b VectorComplex, a VectorComplex, y VectorComplex, x VectorComplex) VectorComplex
- func Hamming(input VectorComplex) VectorComplex
- func Hann(input VectorComplex) VectorComplex
- func IFFT(input VectorComplex) VectorComplex
- func InterpolateC(input VectorComplex, upsampleMultiple int) VectorComplex
- func InverseHamming(input VectorComplex) VectorComplex
- func InverseHann(input VectorComplex) VectorComplex
- func InverseNuttal(input VectorComplex) VectorComplex
- func InverseWindow(windowType WindowType, input VectorComplex) VectorComplex
- func MakeVectorComplex(repeating complex128, count int) VectorComplex
- func MakeVectorComplexFromArray(input []complex128) VectorComplex
- func MakeVectorComplexFromSplit(real Vector, imag Vector) VectorComplex
- func NormalizeStrictC(v VectorComplex) (VectorComplex, []float64)
- func Nuttal(input VectorComplex) VectorComplex
- func VAddC(u VectorComplex, v VectorComplex) VectorComplex
- func VMulEC(u VectorComplex, v VectorComplex) VectorComplex
- func VNegC(v VectorComplex) VectorComplex
- func VSAddC(v VectorComplex, s complex128) VectorComplex
- func VSDivC(v VectorComplex, s complex128) VectorComplex
- func VSMulC(v VectorComplex, s complex128) VectorComplex
- func VSSubC(v VectorComplex, s complex128) VectorComplex
- func VSubC(u VectorComplex, v VectorComplex) VectorComplex
- func Window(windowType WindowType, input VectorComplex) VectorComplex
- func XCorrC(u VectorComplex, v VectorComplex) VectorComplex
- func (v VectorComplex) Conj() VectorComplex
- func (v VectorComplex) Copy() VectorComplex
- func (v VectorComplex) Imag() Vector
- func (v VectorComplex) IsCloseToVectorC(u VectorComplex, tolerance float64) bool
- func (v VectorComplex) IsZero() bool
- func (v VectorComplex) Padded(leadingValue complex128, leadingCount int, trailingValue complex128, ...) VectorComplex
- func (v VectorComplex) PaddedLeading(leadingValue complex128, leadingCount int) VectorComplex
- func (v VectorComplex) PaddedTrailing(trailingValue complex128, trailingCount int) VectorComplex
- func (v VectorComplex) Real() Vector
- func (v VectorComplex) Reverse(start int, stop int) VectorComplex
- func (v VectorComplex) Reversed() VectorComplex
- func (v VectorComplex) SubVector(start int, stop int) VectorComplex
- type WindowType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComplexRI ¶
func ComplexRI(r int) complex128
ComplexRI creates a complex number from a real integer.
func FilterC ¶
func FilterC(b VectorComplex, a VectorComplex, x VectorComplex, z VectorComplex) (VectorComplex, VectorComplex)
FilterC performs a 1-dimensional digital filter.
func FrequencyExtrapolate ¶ added in v1.0.1
func FrequencyExtrapolate(input Vector, count int, windowLength int, windowType WindowType) (Vector, Vector)
FrequencyExtrapolate extrapolates a signal by extrapolating its frequency component signals.
func IsClose ¶
IsClose returns whether or not the distance between values a and b is less than or equal to the given tolerance.
func IsCloseC ¶
func IsCloseC(a complex128, b complex128, tolerance float64) bool
IsCloseC returns whether or not the distance between values a and b is less than or equal to the given tolerance.
func MaxImag ¶
func MaxImag(v VectorComplex) float64
MaxImag returns the maximum value from a slice of floats.
func MaxReal ¶
func MaxReal(v VectorComplex) float64
MaxReal returns the maximum value from a slice of floats.
func MinImag ¶
func MinImag(v VectorComplex) float64
MinImag returns the minimum value from a slice of floats.
func MinReal ¶
func MinReal(v VectorComplex) float64
MinReal returns the minimum value from a slice of floats.
func VESumC ¶
func VESumC(v VectorComplex) complex128
VESumC adds together the elements of v and returns the result.
func VMulESum ¶
VMulESum performs vector element to vector element multiplication, adds the products and returns the resulting sum.
s += u[i] * v[i]
func VMulESumC ¶
func VMulESumC(u VectorComplex, v VectorComplex) complex128
VMulESumC performs vector element to vector element multiplication, adds the products and returns the resulting sum.
s += u[i] * v[i]
func VSumSqC ¶
func VSumSqC(v VectorComplex) complex128
VSumSqC adds together the squared elements of u and returns the result.
Types ¶
type Matrix ¶
type Matrix []Vector
Matrix types represent an array of vectors.
func MakeMatrix ¶
MakeMatrix creates and returns a new matrix in row major order.
type MatrixComplex ¶
type MatrixComplex []VectorComplex
MatrixComplex types represent an array of complex vectors.
func MakeMatrixComplex ¶
func MakeMatrixComplex(repeating complex128, rows int, columns int) MatrixComplex
MakeMatrixComplex creates and returns a new matrix in row major order.
func Spectrogram ¶ added in v1.0.1
func Spectrogram(input Vector, windowLength int, windowType WindowType) MatrixComplex
Spectrogram calculates a spectrogram from the given input signal using the specified window length and type.
func (MatrixComplex) FlipOrderComplex ¶ added in v1.0.1
func (m MatrixComplex) FlipOrderComplex() MatrixComplex
FlipOrderComplex reverses the row and column order when indexing the matrix. The NewMatrix... constructors assume row major order and it is up to the programmer to keep track of what order their instance of Matrix has.
type Vector ¶
type Vector []float64
Vector types represent a real-valued vector.
func ACorr ¶
ACorr performs autocorrelation on real-valued vector u. The output vector has length 2 * len(u) - 1.
func Arburg ¶
Arburg finds the autoregressive parameters for a model with order p using Burg's method on the real-valued input vector, x, and returns the parameters along with the estimated variance.
func Conv ¶
Conv performs convolution on real-valued vectors u and v. The output vector has length len(v) - len(u) + 1.
func Extrapolate ¶
Extrapolate extrapolates the given real-valued signal by n samples using an autoregressive model.
func Filtic ¶
Filtic creates the initial condition vector for the filter function. x (optional) and y contain the last input and output from the filter function. a and b are the filter coefficients.
func GaussianLowpass ¶
GaussianLowpass performs a gaussian lowpass filter on the input signal.
func Interpolate ¶
Interpolate interpolates a real-valued signal using a discrete Fourier transform.
func InverseSpectrogram ¶ added in v1.0.1
func InverseSpectrogram(spectrogram MatrixComplex, windowType WindowType) Vector
InverseSpectrogram calculates a signal from a spectrogram that was generated with the given window type.
func MakeVector ¶
MakeVector creates a new vector.
func MakeVectorFromArray ¶
MakeVectorFromArray creates and returns a new vector from an array.
func NormalizeStrict ¶
NormalizeStrict normalizes a vector using the max and min elements.
func VMagC ¶ added in v1.0.2
func VMagC(v VectorComplex) Vector
VMagC sets each element of the vector to its magnitude.
func VMulE ¶
VMulE performs vector element to vector element multiplication and returns the result.
v[i] *= u[i]
func VSAdd ¶ added in v1.0.3
VSAdd performs vector-scaler addition and returns the result.
v[i] += s
func VSSub ¶ added in v1.0.3
VSSub performs vector-scaler subtraction and returns the result.
v[i] -= s
func XCorr ¶
XCorr performs cross-correlation on real-valued vectors u and v. The output vector has length len(v) - len(u) + 1.
func (Vector) IsCloseToVector ¶
IsCloseToVector determines if the values of the vector are within the given tolerance of vector u.
func (Vector) IsZero ¶
IsZero checks the elements of u and returns false iff any real or imaginary component is non-zero.
func (Vector) Padded ¶
func (v Vector) Padded(leadingValue float64, leadingCount int, trailingValue float64, trailingCount int) Vector
Padded pads a vector with leading and trailing values.
func (Vector) PaddedLeading ¶
PaddedLeading pads a vector with leading values.
func (Vector) PaddedTrailing ¶
PaddedTrailing pads a vector with trailing values.
func (Vector) Reverse ¶
Reverse reverses the vector by copying and returning the elements from the provided start to stop indexes.
func (Vector) ToComplex ¶
func (v Vector) ToComplex() VectorComplex
ToComplex converts a real-valued vector to a complex-valued vector.
type VectorComplex ¶
type VectorComplex []complex128
VectorComplex types represent a complex-valued vector.
func ACorrC ¶
func ACorrC(u VectorComplex) VectorComplex
ACorrC performs autocorrelation on complex-valued vector u. The output vector has length 2 * len(u) - 1.
func ArburgC ¶
func ArburgC(x VectorComplex, p int) (VectorComplex, complex128)
ArburgC finds the autoregressive parameters for a model with order p using Burg's method on the complex-valued input vector, x, and returns the parameters along with the estimated variance.
func ConvC ¶
func ConvC(u VectorComplex, v VectorComplex) VectorComplex
ConvC performs convolution on complex-valued vectors u and v. The output vector has length len(v) - len(u) + 1.
func DFT ¶
func DFT(input VectorComplex, forward bool) VectorComplex
DFT performs a discrete Fourier transform on the complex-valued input vector and returns the result. Pass true for the forward parameter to perform a forward transform and false for an inverse transform.
func ExtrapolateC ¶
func ExtrapolateC(input VectorComplex, count int) VectorComplex
ExtrapolateC extrapolates the given complex-valued signal by n samples using an autoregressive model.
func FFT ¶
func FFT(input VectorComplex) VectorComplex
FFT performs a discrete Fourier transform on the complex-valued input vector using the Cooley-Turkey FFT algorithm. For an inverse FFT, see the IFFT function.
func FilticC ¶
func FilticC(b VectorComplex, a VectorComplex, y VectorComplex, x VectorComplex) VectorComplex
FilticC creates the initial condition vector for the filter function. x (optional) and y contain the last input and output from the filter function. a and b are the filter coefficients.
func Hamming ¶
func Hamming(input VectorComplex) VectorComplex
Hamming performs Hamming windowing on the input vector.
func Hann ¶
func Hann(input VectorComplex) VectorComplex
Hann performs Hann windowing on the input vector.
func IFFT ¶
func IFFT(input VectorComplex) VectorComplex
IFFT performs an inverse discrete Fourier transform on the complex-valued input vector using the Cooley-Turkey FFT algorithm. For a forward FFT, see the FFT function.
func InterpolateC ¶
func InterpolateC(input VectorComplex, upsampleMultiple int) VectorComplex
InterpolateC interpolates a complex-valued signal using a discrete Fourier transform.
func InverseHamming ¶
func InverseHamming(input VectorComplex) VectorComplex
InverseHamming performs inverse Hamming windowing on the input vector.
func InverseHann ¶
func InverseHann(input VectorComplex) VectorComplex
InverseHann performs inverse Hann windowing on the input vector.
func InverseNuttal ¶
func InverseNuttal(input VectorComplex) VectorComplex
InverseNuttal performs inverse Nuttal windowing on the input vector.
func InverseWindow ¶ added in v1.0.1
func InverseWindow(windowType WindowType, input VectorComplex) VectorComplex
InverseWindow applies an inverse window function given by windowType to the input signal.
func MakeVectorComplex ¶
func MakeVectorComplex(repeating complex128, count int) VectorComplex
MakeVectorComplex creates a new vector.
func MakeVectorComplexFromArray ¶
func MakeVectorComplexFromArray(input []complex128) VectorComplex
MakeVectorComplexFromArray creates and returns a new vector from an array.
func MakeVectorComplexFromSplit ¶
func MakeVectorComplexFromSplit(real Vector, imag Vector) VectorComplex
MakeVectorComplexFromSplit creates a new vector from real and imaginary parts.
func NormalizeStrictC ¶
func NormalizeStrictC(v VectorComplex) (VectorComplex, []float64)
NormalizeStrictC normalizes a complex-valued vector.
func Nuttal ¶
func Nuttal(input VectorComplex) VectorComplex
Nuttal performs Nuttal windowing on the input vector.
func VAddC ¶
func VAddC(u VectorComplex, v VectorComplex) VectorComplex
VAddC performs vector addition and returns the result.
v[i] += u[i]
func VMulEC ¶
func VMulEC(u VectorComplex, v VectorComplex) VectorComplex
VMulEC performs vector element to vector element multiplication and returns the result.
v[i] *= u[i]
func VNegC ¶
func VNegC(v VectorComplex) VectorComplex
VNegC returns the additive inverse of v.
VSMulC(v, -1.0)
func VSAddC ¶ added in v1.0.3
func VSAddC(v VectorComplex, s complex128) VectorComplex
VSAddC performs vector-scaler addition and returns the result.
v[i] += s
func VSDivC ¶
func VSDivC(v VectorComplex, s complex128) VectorComplex
VSDivC performs vector-scaler division and returns the result.
v[i] /= s
func VSMulC ¶
func VSMulC(v VectorComplex, s complex128) VectorComplex
VSMulC performs vector-scaler multiplication and returns the result.
v[i] *= s
func VSSubC ¶ added in v1.0.3
func VSSubC(v VectorComplex, s complex128) VectorComplex
VSSubC performs vector-scaler subtraction and returns the result.
v[i] -= s
func VSubC ¶
func VSubC(u VectorComplex, v VectorComplex) VectorComplex
VSubC performs vector subtraction and returns the result.
v[i] -= u[i]
func Window ¶ added in v1.0.1
func Window(windowType WindowType, input VectorComplex) VectorComplex
Window applies a window function given by windowType to the input signal.
func XCorrC ¶
func XCorrC(u VectorComplex, v VectorComplex) VectorComplex
XCorrC performs cross-correlation on complex-valued vectors u and v. The output vector has length len(v) - len(u) + 1.
func (VectorComplex) Conj ¶
func (v VectorComplex) Conj() VectorComplex
Conj returns conjugate vector.
func (VectorComplex) Copy ¶
func (v VectorComplex) Copy() VectorComplex
Copy creates and returns a new vector initializes with the elements of v.
func (VectorComplex) Imag ¶
func (v VectorComplex) Imag() Vector
Imag returns the imaginary components of the vector.
func (VectorComplex) IsCloseToVectorC ¶
func (v VectorComplex) IsCloseToVectorC(u VectorComplex, tolerance float64) bool
IsCloseToVectorC determines if the values of the vector are within the given tolerance of vector u.
func (VectorComplex) IsZero ¶
func (v VectorComplex) IsZero() bool
IsZero checks the elements of u and returns false iff any real or imaginary component is non-zero.
func (VectorComplex) Padded ¶
func (v VectorComplex) Padded(leadingValue complex128, leadingCount int, trailingValue complex128, trailingCount int) VectorComplex
Padded pads a vector with leading and trailing values.
func (VectorComplex) PaddedLeading ¶
func (v VectorComplex) PaddedLeading(leadingValue complex128, leadingCount int) VectorComplex
PaddedLeading pads a vector with leading values.
func (VectorComplex) PaddedTrailing ¶
func (v VectorComplex) PaddedTrailing(trailingValue complex128, trailingCount int) VectorComplex
PaddedTrailing pads a vector with trailing values.
func (VectorComplex) Real ¶
func (v VectorComplex) Real() Vector
Real returns the real componenets of the vector.
func (VectorComplex) Reverse ¶
func (v VectorComplex) Reverse(start int, stop int) VectorComplex
Reverse reverses the vector by copying and returning the elements from the provided start to stop indexes.
func (VectorComplex) Reversed ¶
func (v VectorComplex) Reversed() VectorComplex
Reversed reverses the vector.
func (VectorComplex) SubVector ¶
func (v VectorComplex) SubVector(start int, stop int) VectorComplex
SubVector returns a subvector.
type WindowType ¶ added in v1.0.1
type WindowType int
WindowType values represent a window function and its inverse.
const ( WindowTypeHann WindowType = iota + 1 WindowTypeHamming WindowTypeNuttal )
Types of windows.