assay

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyBlackmanWindow

func ApplyBlackmanWindow(samples []float64) []float64

func ApplyHammingWindow

func ApplyHammingWindow(samples []float64) []float64

func ApplyHannWindow

func ApplyHannWindow(samples []float64) []float64

func CalculateBandwidth

func CalculateBandwidth(peaks []int, frequencies []float64) float64

CalculateBandwidth calculates the frequency range (bandwidth) of the signal based on the provided peaks and their corresponding frequencies.

func CalculateEnergyDensityByBand

func CalculateEnergyDensityByBand(magnitudes, frequences []float64, numBands int) []float64

CalculateEnergyDensityByBand calculates the energy density for each frequency band, showing how energy is distributed across frequency ranges. It helps identify where the energy is concentrated: low, mid, or high frequencies. Example: A bass sound has high energy in low frequencies, while a cymbal or synthetic drum sound carries more energy in high frequencies.

func CalculateSpectralCentroid

func CalculateSpectralCentroid(magnitudes, frequences []float64) float64

CalculateSpectralCentroid computes the spectral centroid, which is the weighted average of the frequencies based on their magnitudes.

func CalculateSpectralContrast

func CalculateSpectralContrast(magnitudes []float64, frequences []float64, numBands int) []float64

CalculateSpectralContrast calculates the spectral contrast, measuring energy differences across frequency bands. It helps distinguish uniform energy sounds from those with prominent frequency differences. Low contrast: Uniform energy, as in white noise or synthetic sounds. High contrast: Significant energy differences, as in drums, where low frequencies dominate.

func CalculateSpectralSlope

func CalculateSpectralSlope(magnitudes, frequences []float64) float64

CalculateSpectralSlope calculates the spectral slope, which indicates how higher frequencies relate to lower frequencies. It helps identify whether a sound is "bright" or "dull". Dull sounds: Typically have a steeper spectral slope, with less energy at higher frequencies. Bright sounds: Have a flatter spectral slope, with more energy at higher frequencies.

func CalculateThreshold

func CalculateThreshold(magnitudes []float64) float64

CalculateThreshold calculates a dynamic threshold based on the magnitude values

func CalculateTimeVaryingVolume

func CalculateTimeVaryingVolume(samples []float64, windowSize int) []float64

CalculateTimeVaryingVolume calculates the time-varying volume (envelope) by computing the amplitude energy within a sliding window (e.g., 1024 samples) and moving the window across time, updating the volume value at each step.

func CalculateTotalEnergyDensity

func CalculateTotalEnergyDensity(magnitudes []float64) float64

CalculateTotalEnergyDensity calculates the total energy density of a sound.

func CalculateVolumeInBand

func CalculateVolumeInBand(magnitudes []float64, freqs []float64, targetFreq float64, bandwidth float64) float64

CalculateVolumeInBand calculates the volume within a specific frequency band by summing the magnitudes of frequencies around a target frequency and its bandwidth.

func CountValuesInBinsInRange

func CountValuesInBinsInRange(values []float64, minValue, maxValue float64, numBins int) []int

CountValuesInBinsInRange counts how many values fall into each bin within the specified range and returns the number of values in each bin.

func ExportFFTResultsToCSV

func ExportFFTResultsToCSV(frequencies, magnitudes, phases []float64, filename string) error

ExportFFTResultsToCSV exports extracted FFT results to CSV. With float values: freq in Hz, magnitude, phase in rad.

func ExportRawFFTToCSV

func ExportRawFFTToCSV(fftResult []complex128, sampleRate float64, filename string) error

ExportRawFFTToCSV exports FFT results to CSV. With float values: freq in Hz, magnitude, phase in rad.

func ExtractFFTResults

func ExtractFFTResults(spectrum []complex128, sampleRate float64) ([]float64, []float64, []float64)

Convert the FFT result to frequencies, magnitude, and phase (rad). Will only do the left side - 0 to Nyquist-freq.

func FindDominantFrequencyIdx

func FindDominantFrequencyIdx(magnitudes []float64) int

FindDominantFrequencyIdx returns the index of the highest magnitude.

func FindPeakIdxsWithPercentageThreshold

func FindPeakIdxsWithPercentageThreshold(magnitudes []float64, threshold float64) []int

FindPeakIdxsWithPercentageThreshold returns the indexes of magnitudes whose ratio to the maximum magnitude exceeds the given percentage threshold.

func FindPeakIdxsWithThreshold

func FindPeakIdxsWithThreshold(magnitudes []float64, threshold float64) []int

FindPeakIdxsWithThreshold returns the indexes of magnitudes which are above a given threshold.

func GetAttackTime

func GetAttackTime(samples []float64, sampleRate int) float64

GetAttackTime calculates the attack time of a sound, which indicates how quickly the sound reaches its maximum volume from silence.

func GetBlackmanWindow

func GetBlackmanWindow(size int) []float64

Strongest side-lobe suppression of the three, but the main lobe is wider, reducing frequency resolution. Ideal for applications where minimizing side-lobes is critical, even at the expense of less sharp frequency peaks.

func GetFFTForFullSample

func GetFFTForFullSample(sample []float64) []complex128

Advantage: Provides the highest frequency resolution, which is ideal for identifying fine frequency details in stationary signals. Use case: Use this method when the signal doesn't change much over time and you're primarily interested in frequency precision.

func GetFFTWithOverlappingWindows

func GetFFTWithOverlappingWindows(sample []float64, windowSize int, overlap int) [][]complex128

Advantage: Provides a balance between frequency and time resolution. By averaging over multiple windows with overlap, you get smoother spectral analysis. Use case: Useful for analyzing non-stationary signals while maintaining good frequency and time resolution.

func GetFFTWithShorterWindows

func GetFFTWithShorterWindows(sample []float64, windowSize int) [][]complex128

Advantage: Better time resolution; allows you to capture how the frequencies change over time, though at the cost of frequency resolution. Use case: Ideal for signals where you want to observe frequency changes over time.

func GetHammingWindow

func GetHammingWindow(size int) []float64

Better side-lobe suppression than Hann, but slightly worse frequency resolution. Useful when minimizing spectral leakage is more important than precise frequency localization.

func GetHannWindow

func GetHannWindow(size int) []float64

Moderate side-lobe suppression with good frequency resolution. Suitable for general-purpose use when no specific windowing requirements exist.

func GetMagnitudePercentageDistribution

func GetMagnitudePercentageDistribution(magnitudes []float64, bucketCount int) []int

GetMagnitudePercentageDistribution converts magnitudes to percentage ratios relative to the highest value and groups them into buckets.

func GetMagnitudesAsPercentage

func GetMagnitudesAsPercentage(magnitudes []float64) []float64

GetMagnitudesAsPercentage converts magnitudes to percentage ratios relative to the highest magnitude.

func GetZeroCrossingRate

func GetZeroCrossingRate(samples []float64) float64

GetZeroCrossingRate computes the Zero Crossing Rate (ZCR) of the given audio samples. The ZCR represents the rate at which the signal changes sign (crosses the zero amplitude level). Higher ZCR suggests noisier or higher-frequency sounds, while lower ZCR indicates deeper, clearer sounds.

func PlotBins

func PlotBins(bins []int, minValue, maxValue, numBins int, filename string) error

PlotBins draws a diagram based on the values in the provided bins, with specified minimum and maximum values, and saves it to a file.

func PlotMagnitudeAndPhase

func PlotMagnitudeAndPhase(frequencies, magnitudes, phases []float64, filename string) error

PlotMagnitudeAndPhase generates two aligned plots: magnitude/frequency and phase/frequency, displayed one below the other.

Types

This section is empty.

Jump to

Keyboard shortcuts

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