dsp

package
v0.0.0-...-50abb7e Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyWindow

func ApplyWindow(arr []float64, wf WindowFunc)

ApplyWindow applies the provided window on the given array

func DFT

func DFT(arr []float64) []float64

DFT is a discrete fourier transform implementation (it is slow O(N^2)) TODO parallelize ?

func Downsample

func Downsample(arr []float64, ratio int) []float64

Downsample downsamples the given array using the given ratio by averaging

func FFT

func FFT(in []float64) []float64

FFT is a fast fourier transform using gonum/fourier TODO remove adding duplicate frequencies (it's ~33% slower with them)

func HammingWindow

func HammingWindow(M int) []float64

HammingWindow is a hamming window the formula used is w(n) = 0.54 - 0.46 * cos(2 * pi * n / (M - 1)) for M in [0, M-1]

func MatchScore

func MatchScore(sample, match map[model.EncodedKey]model.TableValue) float64

MatchScore computes a match score between the two transformed audio samples (into a list of Key + TableValue)

func Reshape

func Reshape(arr []float64, size int) [][]float64

Reshape takes an array and a bin size and will split the given array into multiple bins of the given bin size if len(arr) % size != 0, the data at the end will be dropped XXX: maybe don't drop it ?

func SpecToImg

func SpecToImg(matrix [][]float64) image.Image

SpecToImg takes a spectrogram (matrix of floats representing m[time][frequency] = amplitude) and return an image

Types

type Filterer

type Filterer interface {
	Filter(arr []float64) []float64
}

Filterer is the interface used for filters

type LPFilter

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

LPFilter is a first order low pass filter usig H(p) = 1 / (1 + pRC)

func NewLPFilter

func NewLPFilter(cutoff, sampleRate float64) *LPFilter

NewLPFilter creates a new low pass Filter

func (*LPFilter) Filter

func (lp *LPFilter) Filter(arr []float64) []float64

XXX: This filter could be improved Filter filters the given array of values, panics if array is empty

type Spectrogrammer

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

Spectrogrammer is a struct that allows to create spectrograms

func NewSpectrogrammer

func NewSpectrogrammer(dsRatio, maxFreq, binSize float64, windowing bool) *Spectrogrammer

NewSpectrogrammer creates a new spectrogrammer

func (*Spectrogrammer) ConstellationMap

func (s *Spectrogrammer) ConstellationMap(spec [][]float64, sampleRate float64) []model.ConstellationPoint

ConstellationMap takes a spectrogram, its sample rate and returns the highest frequencies and their time in the audio file The returned slice is ordered by time and is ordered by frequency for a constant time: If two time-frequency points have the same time, the time-frequency point with the lowest frequency is before the other one. If a time time-frequency point has a lower time than another point one then it is before.

func (*Spectrogrammer) Spectrogram

func (s *Spectrogrammer) Spectrogram(file *os.File) ([][]float64, float64, error)

Spectrogram reads the provided audio file and returns a spectrogram for it Matrix is in the following format: TIME : FREQUENCY : Value time is t * binSize * dsp.DownsampleRatio / reader.SampleRate() frequency is f * freqBinSize

type WindowFunc

type WindowFunc func(M int) []float64

WindowFunc represents a window function It takes the number of points we want in the output window

Jump to

Keyboard shortcuts

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