go-dsp: github.com/mjibson/go-dsp/dsputils Index | Files

package dsputils

import "github.com/mjibson/go-dsp/dsputils"

Package dsputils provides functions useful in digital signal processing.

Index

Package Files

compare.go dsputils.go matrix.go

func ComplexEqual Uses

func ComplexEqual(a, b complex128) bool

ComplexEqual returns true if a and b are very close, else false.

func Float64Equal Uses

func Float64Equal(a, b float64) bool

Float64Equal returns true if a and b are very close, else false.

func IsPowerOf2 Uses

func IsPowerOf2(x int) bool

IsPowerOf2 returns true if x is a power of 2, else false.

func NextPowerOf2 Uses

func NextPowerOf2(x int) int

NextPowerOf2 returns the next power of 2 >= x.

func PrettyClose Uses

func PrettyClose(a, b []float64) bool

PrettyClose returns true if the slices a and b are very close, else false.

func PrettyClose2 Uses

func PrettyClose2(a, b [][]complex128) bool

PrettyClose2 returns true if the matrixes a and b are very close, else false.

func PrettyClose2F Uses

func PrettyClose2F(a, b [][]float64) bool

PrettyClose2F returns true if the matrixes a and b are very close, else false.

func PrettyCloseC Uses

func PrettyCloseC(a, b []complex128) bool

PrettyCloseC returns true if the slices a and b are very close, else false.

func Segment Uses

func Segment(x []complex128, segs int, noverlap float64) [][]complex128

Segment returns segs equal-length slices that are segments of x with noverlap% of overlap. The returned slices are not copies of x, but slices into it. Trailing entries in x that connot be included in the equal-length segments are discarded. noverlap is a percentage, thus 0 <= noverlap <= 1, and noverlap = 0.5 is 50% overlap.

func ToComplex Uses

func ToComplex(x []float64) []complex128

ToComplex returns the complex equivalent of the real-valued slice.

func ToComplex2 Uses

func ToComplex2(x [][]float64) [][]complex128

ToComplex2 returns the complex equivalent of the real-valued matrix.

func ZeroPad Uses

func ZeroPad(x []complex128, length int) []complex128

ZeroPad returns x with zeros appended to the end to the specified length. If len(x) >= length, x is returned, otherwise a new array is returned.

func ZeroPad2 Uses

func ZeroPad2(x []complex128) []complex128

ZeroPad2 returns ZeroPad of x, with the length as the next power of 2 >= len(x).

func ZeroPadF Uses

func ZeroPadF(x []float64, length int) []float64

ZeroPadF returns x with zeros appended to the end to the specified length. If len(x) >= length, x is returned, otherwise a new array is returned.

type Matrix Uses

type Matrix struct {
    // contains filtered or unexported fields
}

Matrix is a multidimensional matrix of arbitrary size and dimension. It cannot be resized after creation. Arrays in any axis can be set or fetched.

func MakeEmptyMatrix Uses

func MakeEmptyMatrix(dims []int) *Matrix

MakeEmptyMatrix creates an empty Matrix with given dimensions.

func MakeMatrix Uses

func MakeMatrix(x []complex128, dims []int) *Matrix

MakeMatrix returns a new Matrix populated with x having dimensions dims. For example, to create a 3-dimensional Matrix with 2 components, 3 rows, and 4 columns:

MakeMatrix([]complex128 {
  1, 2, 3, 4,
  5, 6, 7, 8,
  9, 0, 1, 2,

  3, 4, 5, 6,
  7, 8, 9, 0,
  4, 3, 2, 1},
[]int {2, 3, 4})

func MakeMatrix2 Uses

func MakeMatrix2(x [][]complex128) *Matrix

MakeMatrix2 is a helper function to convert a 2-d array to a matrix.

func (*Matrix) Copy Uses

func (m *Matrix) Copy() *Matrix

Copy returns a new copy of m.

func (*Matrix) Dim Uses

func (s *Matrix) Dim(dims []int) []complex128

Dim returns the array of any given index of the Matrix. Exactly one value in dims must be -1. This is the array dimension returned. For example, using the Matrix documented in MakeMatrix:

m.Dim([]int {1, 0, -1}) = []complex128 {3, 4, 5, 6}
m.Dim([]int {0, -1, 2}) = []complex128 {3, 7, 1}
m.Dim([]int {-1, 1, 3}) = []complex128 {8, 0}

func (*Matrix) Dimensions Uses

func (m *Matrix) Dimensions() []int

Dimensions returns the dimension array of the Matrix.

func (*Matrix) PrettyClose Uses

func (m *Matrix) PrettyClose(n *Matrix) bool

PrettyClose returns true if the Matrixes are very close, else false. Comparison done using dsputils.PrettyCloseC().

func (*Matrix) SetDim Uses

func (m *Matrix) SetDim(x []complex128, dims []int)

func (*Matrix) SetValue Uses

func (s *Matrix) SetValue(x complex128, dims []int)

SetValue sets the value at the given index. m.SetValue(10, []int {1, 2, 3, 4}) is equivalent to m[1][2][3][4] = 10.

func (*Matrix) To2D Uses

func (m *Matrix) To2D() [][]complex128

To2D returns the 2-D array equivalent of the Matrix. Only works on Matrixes of 2 dimensions.

func (*Matrix) Value Uses

func (s *Matrix) Value(dims []int) complex128

Value returns the value at the given index. m.Value([]int {1, 2, 3, 4}) is equivalent to m[1][2][3][4].

Package dsputils imports 1 packages (graph) and is imported by 9 packages. Updated 2016-07-18. Refresh now. Tools for package owners.