gdsp

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: MIT Imports: 4 Imported by: 0

README

gDSP

GoDoc Build Status

A digital signal processing library for Go.

Features

gDSP is a light-weight vector library with a focus on digital signal processing. It is not meant to replace other more robust linear algebra packages.

Functions
  • Autoregressive model parameters using Burg's method
  • Autocorrelation
  • Convolution
  • Cross-correlation
  • Discrete Fourier transform
  • Fast Fourier transform
  • Extrapolation
  • 1-dimensional digital filter
  • Filter initialization function
  • IIR filter
  • FIR filter
  • Interpolation
  • Gaussian lowpass filter
  • Normalization
Windowing
  • Hann
  • Hamming
  • Nuttal
Vectors
  • Real and complex support
  • Vector arithmetic
  • Padding functions
Matrices
  • Conjugate
  • Determinant
  • Transpose

Documentation

Overview

Package gdsp provides the types and functions necessary to process digital signals.

Index

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 Filter

func Filter(b Vector, a Vector, x Vector, z Vector) (Vector, Vector)

Filter performs a 1-dimensional digital filter.

func FilterC

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

func IsClose(a float64, b float64, tolerance float64) bool

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 Max

func Max(v Vector) float64

Max returns the maximum value from a vector.

func MaxI

func MaxI(n ...int) int

MaxI returns the maximum integer in a set of integers.

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 Mean

func Mean(v Vector) float64

Mean returns the mean of the elements of v.

func Median

func Median(v Vector) float64

Median returns the median of the elements of v.

func Min

func Min(v Vector) float64

Min returns the minimum value from a vector.

func MinI

func MinI(n ...int) int

MinI returns the minimum integer in a set of integers.

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 StdDev

func StdDev(v Vector) float64

StdDev returns the standard deviation of the elements of v.

func VESum

func VESum(v Vector) float64

VESum adds together the elements of v and returns the result.

func VESumC

func VESumC(v VectorComplex) complex128

VESumC adds together the elements of v and returns the result.

func VMulESum

func VMulESum(u Vector, v Vector) float64

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 VSumSq

func VSumSq(v Vector) float64

VSumSq adds together the squared elements of v and returns the result.

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

func MakeMatrix(repeating float64, rows int, columns int) Matrix

MakeMatrix creates and returns a new matrix in row major order.

func (Matrix) FlipOrder added in v1.0.1

func (m Matrix) FlipOrder() Matrix

FlipOrder 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 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

func ACorr(u Vector) Vector

ACorr performs autocorrelation on real-valued vector u. The output vector has length 2 * len(u) - 1.

func Arburg

func Arburg(x Vector, p int) (Vector, float64)

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

func Conv(u Vector, v Vector) Vector

Conv performs convolution on real-valued vectors u and v. The output vector has length len(v) - len(u) + 1.

func Extrapolate

func Extrapolate(input Vector, n int) Vector

Extrapolate extrapolates the given real-valued signal by n samples using an autoregressive model.

func Filtic

func Filtic(b Vector, a Vector, y Vector, x Vector) Vector

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

func GaussianLowpass(input Vector, cutoff float64) Vector

GaussianLowpass performs a gaussian lowpass filter on the input signal.

func IIR

func IIR(input Vector, response float64) Vector

IIR performs an IIR filter on input with the given response.

func Interpolate

func Interpolate(input Vector, upsampleMultiple int) Vector

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

func MakeVector(repeating float64, count int) Vector

MakeVector creates a new vector.

func MakeVectorFromArray

func MakeVectorFromArray(input []float64) Vector

MakeVectorFromArray creates and returns a new vector from an array.

func Normalize

func Normalize(v Vector) Vector

Normalize normalizes the given vector.

func NormalizeStrict

func NormalizeStrict(v Vector) (Vector, []float64)

NormalizeStrict normalizes a vector using the max and min elements.

func VAbs added in v1.0.2

func VAbs(v Vector) Vector

VAbs sets each element of the vector to its absolute value.

func VAdd

func VAdd(u Vector, v Vector) Vector

VAdd performs vector addition and returns the result.

v[i] += u[i]

func VMagC added in v1.0.2

func VMagC(v VectorComplex) Vector

VMagC sets each element of the vector to its magnitude.

func VMulE

func VMulE(u Vector, v Vector) Vector

VMulE performs vector element to vector element multiplication and returns the result.

v[i] *= u[i]

func VNeg

func VNeg(v Vector) Vector

VNeg returns the additive inverse of v.

VSMul(v, -1.0)

func VSDiv

func VSDiv(v Vector, s float64) Vector

VSDiv performs vector-scaler division and returns the result.

v[i] /= s

func VSMul

func VSMul(v Vector, s float64) Vector

VSMul performs vector-scaler multiplication and returns the result.

v[i] *= s

func VSub

func VSub(u Vector, v Vector) Vector

VSub performs vector subtraction and returns the result.

v[i] -= u[i]

func XCorr

func XCorr(u Vector, v Vector) Vector

XCorr performs cross-correlation on real-valued vectors u and v. The output vector has length len(v) - len(u) + 1.

func (Vector) Copy

func (v Vector) Copy() Vector

Copy creates and returns a new vector initializes with the elements of v.

func (Vector) IsCloseToVector

func (v Vector) IsCloseToVector(u Vector, tolerance float64) bool

IsCloseToVector determines if the values of the vector are within the given tolerance of vector u.

func (Vector) IsZero

func (v Vector) IsZero() bool

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

func (v Vector) PaddedLeading(leadingValue float64, leadingCount int) Vector

PaddedLeading pads a vector with leading values.

func (Vector) PaddedTrailing

func (v Vector) PaddedTrailing(trailingValue float64, trailingCount int) Vector

PaddedTrailing pads a vector with trailing values.

func (Vector) Reverse

func (v Vector) Reverse(start int, stop int) Vector

Reverse reverses the vector by copying and returning the elements from the provided start to stop indexes.

func (Vector) Reversed

func (v Vector) Reversed() Vector

Reversed reverses the vector.

func (Vector) SubVector

func (v Vector) SubVector(start int, stop int) Vector

SubVector returns a subvector.

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

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

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

VAddC performs vector addition and returns the result.

v[i] += u[i]

func VMulEC

VMulEC performs vector element to vector element multiplication and returns the result.

v[i] *= u[i]

func VNegC

VNegC returns the additive inverse of v.

VSMulC(v, -1.0)

func VSDivC

VSDivC performs vector-scaler division and returns the result.

v[i] /= s

func VSMulC

VSMulC performs vector-scaler multiplication and returns the result.

v[i] *= s

func VSubC

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

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.

Jump to

Keyboard shortcuts

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