Documentation ¶
Index ¶
- Constants
- func AddScaled(size int, alpha float64) dsp.Processer
- func BlackmanWindow(n int) []float64
- func CheckError(t *testing.T, e error)
- func DCT(inSize, outSize int) dsp.Processer
- func DFTEnergy(dft []float64) []float64
- func Filterbank(indices []int, coeff [][]float64) dsp.Processer
- func GenerateDCT(N, M int) [][]float64
- func GenerateFilterbank(n, nf int, freq ...float64) ([]int, [][]float64)
- func HammingWindow(n int) []float64
- func HanningWindow(n int) []float64
- func Join() dsp.Processer
- func Log() dsp.Processer
- func MSE() dsp.Processer
- func MaxNorm(bufSize int, alpha float64) dsp.Processer
- func MaxWin() dsp.Processer
- func MaxXCorrIndex(lagLimit int) dsp.Processer
- func Mean() dsp.Processer
- func Modulo(a, b int) int
- func RealFT(data []float64, n int, direct bool)
- func RectangularWindow(n int) []float64
- func Scale(alpha float64) dsp.Processer
- func SpectralEnergy(logSize int) dsp.Processer
- func Sub() dsp.Processer
- func Sum() dsp.Processer
- func WindowSlice(winType, winSize int) ([]float64, error)
- func WriteValues(writer io.Writer, on bool) dsp.Processer
- type DiffProc
- type MAProc
- type Value
- type ValueType
- type WindowProc
Constants ¶
const ( // Rectangular window. Rectangular = iota // Hanning window. Hanning // Hamming window. Hamming // Blackman window. Blackman )
Variables ¶
This section is empty.
Functions ¶
func AddScaled ¶
AddScaled adds frames from all inputs and scales the added values. Will panic if input frame sizes don't match.
func BlackmanWindow ¶
BlackmanWindow returns a Blackman window. w(t) = 0.42 – 0.5 * cos(2pt/T) + 0.08 * cos(4pt/T)
func CheckError ¶
func DFTEnergy ¶
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 ¶
Filterbank computes filterbank energies using the provided indices and coefficients.
func GenerateDCT ¶
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 ¶
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 ¶
HammingWindow returns a Hanning window. w(t) = 0.54 – 0.46 * cos(2 pi t / T)
func HanningWindow ¶
HanningWindow returns a Hanning window. w(t) = 0.5 – 0.5 * cos(2 pi t / T)
func Join ¶
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 MaxNorm ¶
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 MaxXCorrIndex ¶
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 ¶
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 RealFT ¶
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 ¶
RectangularWindow returns a rectangular window. w(t) = 1.0
func SpectralEnergy ¶
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 ¶
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 WindowSlice ¶
WindowSlice Returns a window as a slice of float64.
Types ¶
type DiffProc ¶
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 ¶
NewDiffProc returns a new diff processor.
type MAProc ¶
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.
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.