Documentation
¶
Index ¶
- func ApplyBlackmanWindow(samples []float64) []float64
- func ApplyHammingWindow(samples []float64) []float64
- func ApplyHannWindow(samples []float64) []float64
- func CalculateBandwidth(peaks []int, frequencies []float64) float64
- func CalculateEnergyDensityByBand(magnitudes, frequences []float64, numBands int) []float64
- func CalculateSpectralCentroid(magnitudes, frequences []float64) float64
- func CalculateSpectralContrast(magnitudes []float64, frequences []float64, numBands int) []float64
- func CalculateSpectralSlope(magnitudes, frequences []float64) float64
- func CalculateThreshold(magnitudes []float64) float64
- func CalculateTimeVaryingVolume(samples []float64, windowSize int) []float64
- func CalculateTotalEnergyDensity(magnitudes []float64) float64
- func CalculateVolumeInBand(magnitudes []float64, freqs []float64, targetFreq float64, bandwidth float64) float64
- func CountValuesInBinsInRange(values []float64, minValue, maxValue float64, numBins int) []int
- func ExportFFTResultsToCSV(frequencies, magnitudes, phases []float64, filename string) error
- func ExportRawFFTToCSV(fftResult []complex128, sampleRate float64, filename string) error
- func ExtractFFTResults(spectrum []complex128, sampleRate float64) ([]float64, []float64, []float64)
- func FindDominantFrequencyIdx(magnitudes []float64) int
- func FindPeakIdxsWithPercentageThreshold(magnitudes []float64, threshold float64) []int
- func FindPeakIdxsWithThreshold(magnitudes []float64, threshold float64) []int
- func GetAttackTime(samples []float64, sampleRate int) float64
- func GetBlackmanWindow(size int) []float64
- func GetFFTForFullSample(sample []float64) []complex128
- func GetFFTWithOverlappingWindows(sample []float64, windowSize int, overlap int) [][]complex128
- func GetFFTWithShorterWindows(sample []float64, windowSize int) [][]complex128
- func GetHammingWindow(size int) []float64
- func GetHannWindow(size int) []float64
- func GetMagnitudePercentageDistribution(magnitudes []float64, bucketCount int) []int
- func GetMagnitudesAsPercentage(magnitudes []float64) []float64
- func GetZeroCrossingRate(samples []float64) float64
- func PlotBins(bins []int, minValue, maxValue, numBins int, filename string) error
- func PlotMagnitudeAndPhase(frequencies, magnitudes, phases []float64, filename string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyBlackmanWindow ¶
func ApplyHammingWindow ¶
func ApplyHannWindow ¶
func CalculateBandwidth ¶
CalculateBandwidth calculates the frequency range (bandwidth) of the signal based on the provided peaks and their corresponding frequencies.
func CalculateEnergyDensityByBand ¶
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 ¶
CalculateSpectralCentroid computes the spectral centroid, which is the weighted average of the frequencies based on their magnitudes.
func CalculateSpectralContrast ¶
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 ¶
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 ¶
CalculateThreshold calculates a dynamic threshold based on the magnitude values
func CalculateTimeVaryingVolume ¶
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 ¶
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 ¶
CountValuesInBinsInRange counts how many values fall into each bin within the specified range and returns the number of values in each bin.
func ExportFFTResultsToCSV ¶
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 ¶
FindDominantFrequencyIdx returns the index of the highest magnitude.
func FindPeakIdxsWithPercentageThreshold ¶
FindPeakIdxsWithPercentageThreshold returns the indexes of magnitudes whose ratio to the maximum magnitude exceeds the given percentage threshold.
func FindPeakIdxsWithThreshold ¶
FindPeakIdxsWithThreshold returns the indexes of magnitudes which are above a given threshold.
func GetAttackTime ¶
GetAttackTime calculates the attack time of a sound, which indicates how quickly the sound reaches its maximum volume from silence.
func GetBlackmanWindow ¶
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 ¶
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 ¶
Moderate side-lobe suppression with good frequency resolution. Suitable for general-purpose use when no specific windowing requirements exist.
func GetMagnitudePercentageDistribution ¶
GetMagnitudePercentageDistribution converts magnitudes to percentage ratios relative to the highest value and groups them into buckets.
func GetMagnitudesAsPercentage ¶
GetMagnitudesAsPercentage converts magnitudes to percentage ratios relative to the highest magnitude.
func GetZeroCrossingRate ¶
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 ¶
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 ¶
PlotMagnitudeAndPhase generates two aligned plots: magnitude/frequency and phase/frequency, displayed one below the other.
Types ¶
This section is empty.