Documentation
¶
Overview ¶
Package dsputils provides functions useful in digital signal processing.
Index ¶
- func ComplexEqual(a, b complex128) bool
- func Float64Equal(a, b float64) bool
- func IsPowerOf2(x int) bool
- func NextPowerOf2(x int) int
- func PrettyClose(a, b []float64) bool
- func PrettyClose2(a, b [][]complex128) bool
- func PrettyClose2F(a, b [][]float64) bool
- func PrettyCloseC(a, b []complex128) bool
- func Segment(x []complex128, segs int, noverlap float64) [][]complex128
- func ToComplex(x []float64) []complex128
- func ToComplex2(x [][]float64) [][]complex128
- func ZeroPad(x []complex128, length int) []complex128
- func ZeroPad2(x []complex128) []complex128
- func ZeroPadF(x []float64, length int) []float64
- type Matrix
- func (m *Matrix) Copy() *Matrix
- func (s *Matrix) Dim(dims []int) []complex128
- func (m *Matrix) Dimensions() []int
- func (m *Matrix) PrettyClose(n *Matrix) bool
- func (m *Matrix) SetDim(x []complex128, dims []int)
- func (s *Matrix) SetValue(x complex128, dims []int)
- func (m *Matrix) To2D() [][]complex128
- func (s *Matrix) Value(dims []int) complex128
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComplexEqual ¶
func ComplexEqual(a, b complex128) bool
ComplexEqual returns true if a and b are very close, else false.
func Float64Equal ¶
Float64Equal returns true if a and b are very close, else false.
func IsPowerOf2 ¶
IsPowerOf2 returns true if x is a power of 2, else false.
func PrettyClose ¶
PrettyClose returns true if the slices a and b are very close, else false.
func PrettyClose2 ¶
func PrettyClose2(a, b [][]complex128) bool
PrettyClose2 returns true if the matrixes a and b are very close, else false.
func PrettyClose2F ¶
PrettyClose2F returns true if the matrixes a and b are very close, else false.
func PrettyCloseC ¶
func PrettyCloseC(a, b []complex128) bool
PrettyCloseC returns true if the slices a and b are very close, else false.
func Segment ¶
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 ¶
func ToComplex(x []float64) []complex128
ToComplex returns the complex equivalent of the real-valued slice.
func ToComplex2 ¶
func ToComplex2(x [][]float64) [][]complex128
ToComplex2 returns the complex equivalent of the real-valued matrix.
func ZeroPad ¶
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 ¶
func ZeroPad2(x []complex128) []complex128
ZeroPad2 returns ZeroPad of x, with the length as the next power of 2 >= len(x).
Types ¶
type Matrix ¶
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 ¶
MakeEmptyMatrix creates an empty Matrix with given dimensions.
func MakeMatrix ¶
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 ¶
func MakeMatrix2(x [][]complex128) *Matrix
MakeMatrix2 is a helper function to convert a 2-d array to a matrix.
func (*Matrix) Dim ¶
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 ¶
Dimensions returns the dimension array of the Matrix.
func (*Matrix) PrettyClose ¶
PrettyClose returns true if the Matrixes are very close, else false. Comparison done using dsputils.PrettyCloseC().
func (*Matrix) SetDim ¶
func (m *Matrix) SetDim(x []complex128, dims []int)
func (*Matrix) SetValue ¶
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 ¶
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 ¶
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].