proc

package
v0.0.0-...-a7203c7 Latest Latest
Warning

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

Go to latest
Published: May 29, 2015 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Rectangular window.
	Rectangular = iota
	// Hanning window.
	Hanning
	// Hamming window.
	Hamming
	// Blackman window.
	Blackman
)

Variables

This section is empty.

Functions

func AddScaled

func AddScaled(size int, alpha float64) dsp.Processer

AddScaled adds frames from all inputs and scales the added values. Will panic if input frame sizes don't match.

func BlackmanWindow

func BlackmanWindow(n int) []float64

BlackmanWindow returns a Blackman window. w(t) = 0.42 – 0.5 * cos(2pt/T) + 0.08 * cos(4pt/T)

func CheckError

func CheckError(t *testing.T, e error)

func DCT

func DCT(inSize, outSize int) dsp.Processer

DCT returns the Discrete Cosine Transform of the input vector.

func DFTEnergy

func DFTEnergy(dft []float64) []float64

DFTEnergy computes the DFT energy vector. The size of the energy array should be half of the input array.

For the example in RealFT, the output would be:

DFT Energy: 2.25 2.17 1.96 1.63 1.25 0.87 0.54 0.33
            n=0  n=1  n=2  n=3  n=4  n=5  n=6  n=7

param "dft" is the discrete Fourier transform. (See RealfFT for format.)

func Filterbank

func Filterbank(indices []int, coeff [][]float64) dsp.Processer

Filterbank computes filterbank energies using the provided indices and coefficients.

func GenerateDCT

func GenerateDCT(N, M int) [][]float64

GenerateDCT generates the Discrete Cosine Transform.

for i = 0,..,N-1

         M-1
dct[i] = sum x[j] * cos(i(2j+1)PI/M)
         j=0

Return the following N x M transformation matrix:

T(0,0)   T(0,1)   T(0,2)   ... T(0,M-1)
T(1,0)   T(1,1)   T(1,2)   ... T(1,M-1)
T(2,0)   T(2,1)   T(2,2)   ... T(2,M-1)
...
T(N-1,0) T(N-1,1) T(N-1,2) ... T(N-1,M-1)

func GenerateFilterbank

func GenerateFilterbank(n, nf int, freq ...float64) ([]int, [][]float64)

GenerateFilterbank generates overlapping filters of triangular shape. For example for n=256 and nf=10:

   0   1     9
   /\ /\     /\
  /  \  \      \
 /  / \  \      \
+--+--+--+ ... --+
0                255

The start of each filter is calculated as follows:

mid = n / (nf+1),  where mid is half filter width.
w = 2 * mid, where w is the width of the filter
start[i] = i * mid, where start is the start of the filter

The filter coefficients are calculated as follows:

c[j] = j / mid, i={0,..mid}
c[2*mid-j] = c[j]

Example for n = 32, nf = 6:

mid = 32/7 = 4
indices: [0 4 8 12 16 20]
coeff:   [0 0.25 0.5 0.75 1 0.75 0.5 0.25]

To limit the frequency range of the filterbank, you may pass either zero or three frequency arguments as follows:

GenerateFilterbank(n, nf int, fs, minFreq, maxFreq)

where:

fs: sampling frequency in Hz
minFreq is the minimum frequency of the filterbank
maxFreq is the maximum frequency of the filterbank

If the frequency arguments are ommited the range will be 0-fs/2. The maxFreq must be less than fs/2. The filterbank will include only the frequencies in the range specified.

func HammingWindow

func HammingWindow(n int) []float64

HammingWindow returns a Hanning window. w(t) = 0.54 – 0.46 * cos(2 pi t / T)

func HanningWindow

func HanningWindow(n int) []float64

HanningWindow returns a Hanning window. w(t) = 0.5 – 0.5 * cos(2 pi t / T)

func Join

func Join() dsp.Processer

Join stacks multiple input vectors into a single vector. Output vector size equals sum of input vector sizes. Blocks until all input vectors are available.

func Log

func Log() dsp.Processer

Log returns the natural logarithm of the input.

func MSE

func MSE() dsp.Processer

MSE returns the mean squared error of two inputs.

func MaxNorm

func MaxNorm(bufSize int, alpha float64) dsp.Processer

MaxNorm returns a norm value as follows:

define: y[n] = norm[n-1] * alpha where alpha < 1
define: norm(v) as sqrt(v . v) where "." is the dot product.

max[n] = max(y[n], norm(x[n])

The max value is computed in the range {0...idx}

func MaxWin

func MaxWin() dsp.Processer

MaxWin returns the elementwise max vector of the input stream.

func MaxXCorrIndex

func MaxXCorrIndex(lagLimit int) dsp.Processer

MaxXCorrIndex returns the lag that maximizes the cross-correlation between two inputs. The param lagLimit is the highest lag value to be explored. Input vectors may have different lengths.

xcor[i] = x[n] * y[n-i]

Returns the value of i that maximizes xcorr[i] and the max correlation value in a two-dimensional vector. value[0]=lag, value[1]=xcorr

func Mean

func Mean() dsp.Processer

Mean returns the mean vector of the input stream.

       N-1
mean = sum in_frame[i] where mean and in_frame are vectors.
       i=0

func Modulo

func Modulo(a, b int) int

Modulo returns modulo of two numbers.

6 % 5 = 1

-3 % 5 = 2

func RealFT

func RealFT(data []float64, n int, direct bool)

RealFT compute the DFT of a real discrete signal. (Adapted fron Numerical Recipes Book)

Input array is the sequence of real values.

Output is stored in the same array using a strange scheme. The first value is the Re{DFT[0]}, the second value is Re{DFT[N-1]}. Example (all values rounded to first decimal):

Real Input sequence N=16:
 0.5 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

Real DFT (rounded values):
 real[k] sum_n {inArray[n] * cos(alpha * k * n)}
 1.5 1.4 1.2 0.9 0.5 0.1 -0.2 -0.4 -0.5 -0.4 -0.2 0.1 0.5 0.9 1.2 1.4

Imag DFT (rounded values):
 imag[k] sum_n {-inArray[n] * sin(alpha * k * n)}
 0.0 -0.4 -0.7 -0.9 -1.0 -0.9 -0.7 -0.4 0.0 0.4 0.7 0.9 1.0 0.9 0.7 0.4

realft returns:
 1.5 -0.5 1.4 0.4 1.2 0.7 0.9 0.9 0.5 1.0 0.1 0.9 -0.2 0.7 -0.4 0.4
 Re   Re  Re  Im  Re  Im  Re  Im  Re  Im  Re  Im   Re  Im   Re  Im
 n=0  n=8 n=7 n=7 n=6 n=6 n=5 n=5 n=4 n=4 n=3 n=3  n=2 n=2  n=1 n=1
 The first 2 components are real values. The rest of the pairs are {Re, Im}

data is the input array of length n. n the length of the discrete signal. direct=true for direct FFT. Inverse otherwise.

func RectangularWindow

func RectangularWindow(n int) []float64

RectangularWindow returns a rectangular window. w(t) = 1.0

func Scale

func Scale(alpha float64) dsp.Processer

Scale returns a scaled vector.

func SpectralEnergy

func SpectralEnergy(logSize int) dsp.Processer

SpectralEnergy computes the real FFT energy of the input frame. FFT size is 2^(logSize+1) and the size of the output vector is 2^logSize. See dsp.RealFT and dsp.DFTEnergy for details.

func Sub

func Sub() dsp.Processer

Sub subtracts in1 from in0. The inputs can be of type Framer of OneValuer. (The method uses reflection to get the type. For higher performance, implement a custom processor.) Will panic if input frame sizes don't match.

func Sum

func Sum() dsp.Processer

Sum returns the sum of the elements of the input frame.

func WindowSlice

func WindowSlice(winType, winSize int) ([]float64, error)

WindowSlice Returns a window as a slice of float64.

func WriteValues

func WriteValues(writer io.Writer, on bool) dsp.Processer

WriteValues prints each input vector v followed by a newline to writer; and in addition it emits v. Therefore WriteValues() can be used like the "tee" command, which can often be useful for debugging.

Types

type DiffProc

type DiffProc struct {
	*dsp.Proc
	// contains filtered or unexported fields
}

DiffProc computes a weighted difference between samples as follows:

for delta < i < N-delta-1:

         delta-1
diff[i] = sum c_j * { x[i+j+1] - x[i-j-1] }
          j=0

where x is the input data stream, i is the frame index. and N
is the number of frames. For other frame indices replace delta with:

for i <= delta : delta' = i  AND  for i >= N-delta-1: delta' = N-1-i

Param "dim" must match the size of the input vectors. Param "coeff" is the slice of coefficients.

func NewDiffProc

func NewDiffProc(dim, bufSize int, coeff []float64) *DiffProc

NewDiffProc returns a new diff processor.

func (*DiffProc) Get

func (dp *DiffProc) Get(idx int) (dsp.Value, error)

Get implements the dsp.dsp.Processer interface.

type MAProc

type MAProc struct {
	*dsp.Proc
	// contains filtered or unexported fields
}

MAProc computes the average for the last M samples.

for i >= M:
                i
AVG[i] = 1/M * sum X[j]
               j=i-M+1

for 0 < i < M
                i
AVG[i] = 1/(i+1) * sum X[j]
               j=0

Where AVG is the output vector and X is the input vector.

Will panic if output size is different from input size. If param avg in not nil, it will be used as the initial avg for i < M.

func NewMAProc

func NewMAProc(dim, winSize, bufSize int) *MAProc

NewMAProc creates a new MA processor.

func (*MAProc) Get

func (ma *MAProc) Get(idx int) (dsp.Value, error)

Get implements the dsp.dsp.Processer interface.

type Value

type Value *narray.NArray

Value is an multidimensional array that satisfies the framer interface.

type ValueType

type ValueType int
const (
	Text ValueType = iota
	Float64
	Float32
	Int32
	Int16
	Int8
)

type WindowProc

type WindowProc struct {
	StepSize   int
	WinSize    int
	WindowType int

	Centered bool
	*dsp.Proc
	// contains filtered or unexported fields
}

WindowProc is a window processor.

func NewWindowProc

func NewWindowProc(stepSize, winSize, windowType int, centered bool) *WindowProc

NewWindowProc returns a windowing processor. Input must return all source data on index zero.

func (*WindowProc) Get

func (win *WindowProc) Get(idx int) (dsp.Value, error)

Get implements the dsp.Processer interface.

func (*WindowProc) SetInputs

func (win *WindowProc) SetInputs(in ...dsp.Processer)

SetInputs for this processor.

Directories

Path Synopsis
Package speech provides functionality to parametrize digital waveforms.
Package speech provides functionality to parametrize digital waveforms.

Jump to

Keyboard shortcuts

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