Repository navigation
Module_SignalProcessing_Features
Location: Home / Signal processing / Features
The Vorcyc.Mathematics.SignalProcessing.Features namespace contains Harmonic, Perceptual, Pitch, and Spectral for harmonic, perceptual, pitch estimation, and spectral audio features.
All types below are in Vorcyc.Mathematics.SignalProcessing.Features namespace。
📒 Contents
- 🔖 Vorcyc.Mathematics.SignalProcessing.Features.Harmonic class
- 🔖 Vorcyc.Mathematics.SignalProcessing.Features.Perceptual class
- 🔖 Vorcyc.Mathematics.SignalProcessing.Features.Pitch class
- 🔖 Vorcyc.Mathematics.SignalProcessing.Features.Spectral class
Vorcyc.Mathematics.SignalProcessing.Features.Harmonic is a static class providing harmonic spectral feature computation.
-
public static void Peaks(float[] spectrum, int[] peaks, float[] peakFrequencies, int samplingRate, float pitch = -1)- Finds harmonic peaks (peak indices and frequencies) in the spectrum.
- Parameters:
-
spectrum: Spectrum. -
peaks: Array to store computed peak positions. -
peakFrequencies: Array to store computed peak frequencies. -
samplingRate: Sampling rate. -
pitch: Pitch in Hz; negative if unknown.
-
-
public static float Centroid(float[] spectrum, int[] peaks, float[] peakFrequencies)- Computes harmonic centroid.
- Parameters:
-
spectrum: Spectrum. -
peaks: Peak positions (indices in spectrum). -
peakFrequencies: Peak frequencies.
-
- Returns: Harmonic centroid.
-
public static float Spread(float[] spectrum, int[] peaks, float[] peakFrequencies)- Computes harmonic spread.
- Parameters:
-
spectrum: Spectrum. -
peaks: Peak positions (indices in spectrum). -
peakFrequencies: Peak frequencies.
-
- Returns: Harmonic spread.
-
public static float Inharmonicity(float[] spectrum, int[] peaks, float[] peakFrequencies)- Computes inharmonicity.
- Parameters:
-
spectrum: Spectrum. -
peaks: Peak positions (indices in spectrum). -
peakFrequencies: Peak frequencies.
-
- Returns: Inharmonicity.
-
public static float OddToEvenRatio(float[] spectrum, int[] peaks)- Computes odd-to-even ratio.
- Parameters:
-
spectrum: Spectrum. -
peaks: Peak positions (indices in spectrum).
-
- Returns: Odd-to-even ratio.
-
public static float Tristimulus(float[] spectrum, int[] peaks, int n)- Computes tristimulus (component n).
- Parameters:
-
spectrum: Spectrum. -
peaks: Peak positions (indices in spectrum). -
n: Tristimulus component index: 1, 2, or 3.
-
- Returns: Tristimulus component.
The following example uses Harmonic with comments:
using System;
using Vorcyc.Mathematics.SignalProcessing.Features;
public class HarmonicExample
{
public static void Main()
{
// Define spectrum
float[] spectrum = { 0.5f, 0.6f, 0.55f, 0.7f, 0.65f, 0.8f, 0.75f, 0.9f, 0.85f, 1.0f }; int[] peaks = new int[5];
float[] peakFrequencies = new float[5]; int samplingRate = 44100;
// Find harmonic peaks
Harmonic.Peaks(spectrum, peaks, peakFrequencies, samplingRate);
// Compute harmonic centroid
float centroid = Harmonic.Centroid(spectrum, peaks, peakFrequencies);
Console.WriteLine($"Harmonic Centroid: {centroid}");
// Compute harmonic spread
float spread = Harmonic.Spread(spectrum, peaks, peakFrequencies);
Console.WriteLine($"Harmonic Spread: {spread}");
// Compute inharmonicity
float inharmonicity = Harmonic.Inharmonicity(spectrum, peaks, peakFrequencies);
Console.WriteLine($"Inharmonicity: {inharmonicity}");
// Compute odd-to-even ratio
float oddToEvenRatio = Harmonic.OddToEvenRatio(spectrum, peaks);
Console.WriteLine($"Odd to Even Ratio: {oddToEvenRatio}");
// Compute tristimulus components
float tristimulus1 = Harmonic.Tristimulus(spectrum, peaks, 1);
float tristimulus2 = Harmonic.Tristimulus(spectrum, peaks, 2);
float tristimulus3 = Harmonic.Tristimulus(spectrum, peaks, 3);
Console.WriteLine($"Tristimulus 1: {tristimulus1}");
Console.WriteLine($"Tristimulus 2: {tristimulus2}");
Console.WriteLine($"Tristimulus 3: {tristimulus3}");
}
}Vorcyc.Mathematics.SignalProcessing.Features.Perceptual is a static class providing perceptual audio feature computation.
-
public static float Loudness(float[] spectralBands)- Computes perceptual loudness (sum of specific loudness: N'(z) = E(z)^0.23).
- Parameters:
-
spectralBands: Energy array in the given bands.
-
- Returns: Perceptual loudness.
-
public static float Sharpness(float[] spectralBands)- Computes perceptual sharpness (spectral centroid equivalent).
- Parameters:
-
spectralBands: Energy array in the given bands.
-
- Returns: Perceptual sharpness.
The following example uses Perceptual with comments:
using System;
using Vorcyc.Mathematics.SignalProcessing.Features;
public class PerceptualExample
{
public static void Main()
{
// Define band energies
float[] spectralBands = { 0.5f, 0.6f, 0.55f, 0.7f, 0.65f };
// Compute perceptual loudness
float loudness = Perceptual.Loudness(spectralBands);
Console.WriteLine($"Loudness: {loudness}");
// Compute perceptual sharpness
float sharpness = Perceptual.Sharpness(spectralBands);
Console.WriteLine($"Sharpness: {sharpness}");
}
}Vorcyc.Mathematics.SignalProcessing.Features.Pitch is a static class providing pitch estimation and tracking.
-
public static float FromAutoCorrelation(float[] samples, int samplingRate, int startPos = 0, int endPos = -1, float low = 80, float high = 400)- Estimates pitch from samples using autocorrelation.
- Parameters:
-
samples: Sample array. -
samplingRate: Sampling rate. -
startPos: Index of first sample to process in the array. -
endPos: Index of last sample to process in the array (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range.
-
- Returns: Estimated pitch.
-
public static float FromAutoCorrelation(Signal signal, int startPos = 0, int endPos = -1, float low = 80, float high = 400)- Estimates pitch from signal using autocorrelation.
- Parameters:
-
signal: Signal. -
startPos: Index of first sample to process in the signal. -
endPos: Index of last sample to process in the signal (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range.
-
- Returns: Estimated pitch.
-
public static float FromZeroCrossingsSchmitt(float[] samples, int samplingRate, int startPos = 0, int endPos = -1, float lowSchmittThreshold = -1e10f, float highSchmittThreshold = 1e10f)- Estimates pitch from samples using zero-crossings and Schmitt trigger.
- Parameters:
-
samples: Sample array. -
samplingRate: Sampling rate. -
startPos: Index of first sample to process in the array. -
endPos: Index of last sample to process in the array (exclusive). -
lowSchmittThreshold: Schmitt trigger lower threshold. -
highSchmittThreshold: Schmitt trigger upper threshold.
-
- Returns: Estimated pitch.
-
public static float FromZeroCrossingsSchmitt(Signal signal, int startPos = 0, int endPos = -1, float lowSchmittThreshold = -1e10f, float highSchmittThreshold = 1e10f)- Estimates pitch from signal using zero-crossings and Schmitt trigger.
- Parameters:
-
signal: Signal. -
startPos: Index of first sample to process in the signal. -
endPos: Index of last sample to process in the signal (exclusive). -
lowSchmittThreshold: Schmitt trigger lower threshold. -
highSchmittThreshold: Schmitt trigger upper threshold.
-
- Returns: Estimated pitch.
-
public static float FromYin(float[] samples, int samplingRate, int startPos = 0, int endPos = -1, float low = 80, float high = 400, float cmdfThreshold = 0.2f)- Estimates pitch from samples using YIN.
- Parameters:
-
samples: Sample array. -
samplingRate: Sampling rate. -
startPos: Index of first sample to process in the array. -
endPos: Index of last sample to process in the array (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range. -
cmdfThreshold: CMDF threshold.
-
- Returns: Estimated pitch.
-
public static float FromYin(Signal signal, int startPos = 0, int endPos = -1, float low = 80, float high = 400, float cmdfThreshold = 0.2f)- Estimates pitch from signal using YIN.
- Parameters:
-
signal: Signal. -
startPos: Index of first sample to process in the signal. -
endPos: Index of last sample to process in the signal (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range. -
cmdfThreshold: CMDF threshold.
-
- Returns: Estimated pitch.
-
public static float FromHss(Signal signal, int startPos = 0, int endPos = -1, float low = 80, float high = 400, int fftSize = 0)- Estimates pitch from signal using HSS.
- Parameters:
-
signal: Signal. -
startPos: Index of first sample to process in the signal. -
endPos: Index of last sample to process in the signal (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range. -
fftSize: FFT size.
-
- Returns: Estimated pitch.
-
public static float FromHss(float[] spectrum, int samplingRate, float low = 80, float high = 400)- Estimates pitch from spectrum using HSS.
- Parameters:
-
spectrum: Spectrum. -
samplingRate: Sampling rate. -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range.
-
- Returns: Estimated pitch.
-
public static float FromHps(Signal signal, int startPos = 0, int endPos = -1, float low = 80, float high = 400, int fftSize = 0)- Estimates pitch from signal using HPS.
- Parameters:
-
signal: Signal. -
startPos: Index of first sample to process in the signal. -
endPos: Index of last sample to process in the signal (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range. -
fftSize: FFT size.
-
- Returns: Estimated pitch.
-
public static float FromHps(float[] spectrum, int samplingRate, float low = 80, float high = 400)- Estimates pitch from spectrum using HPS.
- Parameters:
-
spectrum: Spectrum. -
samplingRate: Sampling rate. -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range.
-
- Returns: Estimated pitch.
-
public static float FromSpectralPeaks(Signal signal, int startPos = 0, int endPos = -1, float low = 80, float high = 400, int fftSize = 0)- Estimates pitch from signal using spectral peaks.
- Parameters:
-
signal: Signal. -
startPos: Index of first sample to process in the signal. -
endPos: Index of last sample to process in the signal (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range. -
fftSize: FFT size.
-
- Returns: Estimated pitch.
-
public static float FromSpectralPeaks(float[] spectrum, int samplingRate, float low = 80, float high = 400)- Estimates pitch from spectrum using spectral peaks.
- Parameters:
-
spectrum: Spectrum. -
samplingRate: Sampling rate. -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range.
-
- Returns: Estimated pitch.
-
public static float FromCepstrum(Signal signal, int startPos = 0, int endPos = -1, float low = 80, float high = 400, int cepstrumSize = 256, int fftSize = 1024)- Estimates pitch from signal using cepstrum.
- Parameters:
-
signal: Signal. -
startPos: Index of first sample to process in the signal. -
endPos: Index of last sample to process in the signal (exclusive). -
low: Lower bound of expected pitch range. -
high: Upper bound of expected pitch range. -
cepstrumSize: Cepstrum size. -
fftSize: FFT size.
-
- Returns: Estimated pitch.
The following example uses Pitch with comments:
using System;
using Vorcyc.Mathematics.SignalProcessing;
using Vorcyc.Mathematics.SignalProcessing.Features;
using Vorcyc.Mathematics.SignalProcessing.Signals;
public class PitchExample
{
public static void Main()
{
// Define input signal
float[] samples = { 0.5f, 0.6f, 0.55f, 0.7f, 0.65f }; var signal = Signal.FromCopy(samples, 44100f);
// Estimate pitch using autocorrelation
float pitchAutoCorrelation = Pitch.FromAutoCorrelation(signal);
Console.WriteLine($"Pitch (AutoCorrelation): {pitchAutoCorrelation} Hz");
// Estimate pitch using zero-crossings and Schmitt trigger
float pitchZeroCrossingsSchmitt = Pitch.FromZeroCrossingsSchmitt(signal);
Console.WriteLine($"Pitch (ZeroCrossingsSchmitt): {pitchZeroCrossingsSchmitt} Hz");
// Estimate pitch using YIN
float pitchYin = Pitch.FromYin(signal);
Console.WriteLine($"Pitch (Yin): {pitchYin} Hz");
// Estimate pitch using HSS
float pitchHss = Pitch.FromHss(signal);
Console.WriteLine($"Pitch (Hss): {pitchHss} Hz");
// Estimate pitch using HPS
float pitchHps = Pitch.FromHps(signal);
Console.WriteLine($"Pitch (Hps): {pitchHps} Hz");
// Estimate pitch from spectral peaks
float pitchSpectralPeaks = Pitch.FromSpectralPeaks(signal);
Console.WriteLine($"Pitch (SpectralPeaks): {pitchSpectralPeaks} Hz");
// Estimate pitch from cepstrum
float pitchCepstrum = Pitch.FromCepstrum(signal);
Console.WriteLine($"Pitch (Cepstrum): {pitchCepstrum} Hz");
}
}Vorcyc.Mathematics.SignalProcessing.Features.Spectral is a static class providing spectral feature computation.
-
public static float Centroid(float[] spectrum, float[] frequencies)- Computes spectral centroid.
- Parameters:
-
spectrum: Spectrum. -
frequencies: Center frequencies.
-
- Returns: Spectral centroid.
-
public static float Spread(float[] spectrum, float[] frequencies)- Computes spectral spread.
- Parameters:
-
spectrum: Spectrum. -
frequencies: Center frequencies.
-
- Returns: Spectral spread.
-
public static float Decrease(float[] spectrum)- Computes spectral decrease.
- Parameters:
-
spectrum: Spectrum.
-
- Returns: Spectral decrease.
-
public static float Flatness(float[] spectrum, float minLevel = 1e-10f)- Computes spectral flatness.
- Parameters:
-
spectrum: Spectrum. -
minLevel: Amplitude threshold.
-
- Returns: Spectral flatness.
-
public static float Noiseness(float[] spectrum, float[] frequencies, float noiseFrequency = 3000)- Computes spectral noisiness.
- Parameters:
-
spectrum: Spectrum. -
frequencies: Center frequencies. -
noiseFrequency: Lower frequency bound for noise.
-
- Returns: Spectral noisiness.
-
public static float Rolloff(float[] spectrum, float[] frequencies, float rolloffPercent = 0.85f)- Computes spectral rolloff frequency.
- Parameters:
-
spectrum: Spectrum. -
frequencies: Center frequencies. -
rolloffPercent: Rolloff percentage.
-
- Returns: Spectral rolloff frequency.
-
public static float Crest(float[] spectrum)- Computes spectral crest.
- Parameters:
-
spectrum: Spectrum.
-
- Returns: Spectral crest.
-
public static float[] Contrast(float[] spectrum, float[] frequencies, float minFrequency = 200, int bandCount = 6)- Computes spectral contrast array across bands.
- Parameters:
-
spectrum: Spectrum. -
frequencies: Center frequencies. -
minFrequency: Start frequency. -
bandCount: Number of spectral bands.
-
- Returns: Spectral contrast array.
-
public static float Contrast(float[] spectrum, float[] frequencies, int bandNo, float minFrequency = 200)- Computes spectral contrast for band index
bandNo. - Parameters:
-
spectrum: Spectrum. -
frequencies: Center frequencies. -
bandNo: Spectral band index. -
minFrequency: Start frequency.
-
- Returns: Spectral contrast.
- Computes spectral contrast for band index
-
public static float Entropy(float[] spectrum)- Computes Shannon entropy of spectrum (treated as PDF).
- Parameters:
-
spectrum: Spectrum.
-
- Returns: Shannon entropy of spectrum.
The following example uses Spectral with comments:
using System;
using Vorcyc.Mathematics.SignalProcessing.Features;
public class SpectralExample
{
public static void Main()
{
// Define spectrum and center frequencies
float[] spectrum = { 0.5f, 0.6f, 0.55f, 0.7f, 0.65f, 0.8f, 0.75f, 0.9f, 0.85f, 1.0f };
float[] frequencies = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
// Compute spectral centroid
float centroid = Spectral.Centroid(spectrum, frequencies);
Console.WriteLine($"Spectral Centroid: {centroid}");
// Compute spectral spread
float spread = Spectral.Spread(spectrum, frequencies);
Console.WriteLine($"Spectral Spread: {spread}");
// Compute spectral decrease
float decrease = Spectral.Decrease(spectrum);
Console.WriteLine($"Spectral Decrease: {decrease}");
// Compute spectral flatness
float flatness = Spectral.Flatness(spectrum);
Console.WriteLine($"Spectral Flatness: {flatness}");
// Compute spectral noisiness
float noiseness = Spectral.Noiseness(spectrum, frequencies);
Console.WriteLine($"Spectral Noiseness: {noiseness}");
// Compute spectral rolloff
float rolloff = Spectral.Rolloff(spectrum, frequencies);
Console.WriteLine($"Spectral Rolloff: {rolloff}");
// Compute spectral crest
float crest = Spectral.Crest(spectrum);
Console.WriteLine($"Spectral Crest: {crest}");
// Compute spectral contrast array
float[] contrast = Spectral.Contrast(spectrum, frequencies);
Console.WriteLine("Spectral Contrast:");
foreach (var value in contrast)
{
Console.WriteLine(value);
}
// Compute spectral entropy
float entropy = Spectral.Entropy(spectrum);
Console.WriteLine($"Spectral Entropy: {entropy}");
}
}-
- 🔖 ArrayExtension class
- 🔖 BaseConverter class
- 🔖 BitMathExtension class
- 🔖 Combinatorics class
- 🔖 ConstantsFp32 class
- 🔖 NumberMapper class
- 🔖 PinnableArray<T> class
- 🔖 SimpleRNG_Fp32 and SimpleRNG_Fp64 classes
- 🔖 TrigonometryHelper class
- 🔖 VMath class
- 🔖 Pinned buffers (Buffers)
- 🔖 IPinnedBuffer<T> interface
- 🔖 POHBuffer<T> class
- 🔖 NativeBuffer<T> class
-
- 🔖 0.9 classifier walkthrough
- 🔖 KNN<T> class
- 🔖 MultipleLinearRegression<T> class
- 🔖 SimpleLinearRegression<T> class
- 🔖 SupportVectorMachine<TSelf> class
- 🔖 DBSCAN<T> class
- 🔖 ExpectationMaximization<T> class
- 🔖 GMM<T> class
- 🔖 HierarchicalClustering<T> class
- 🔖 KMeansClusterer<T> class
- 🔖 VectorQuantization<T> class
- 🔖 FactorAnalysis<T> class
- 🔖 PCA<TSelf> class
- 🔖 TSNE<T> class
- 🔖 Distance metric classes
-
📒 Examples
-
📒 GPU 策略说明
- 🔖 为何放弃主包 GPU
- 🔖 当前性能路径
- 🔖 若仍需要更强算力
-
📒 计算上下文模块
-
📒 核心模块
-
📒 深度学习模块
-
📒 线性代数模块
-
📒 机器学习模块
- 🔖 0.9 分类器完整示例
- 🔖 KNN<T> 类
- 🔖 MultipleLinearRegression<T> 类
- 🔖 SimpleLinearRegression<T> 类
- 🔖 SupportVectorMachine<TSelf> 类
- 🔖 DBSCAN<T> 类
- 🔖 ExpectationMaximization<T> 类
- 🔖 GMM<T> 类
- 🔖 HierarchicalClustering<T> 类
- 🔖 KMeansClusterer<T> 类
- 🔖 VectorQuantization<T> 类
- 🔖 FactorAnalysis<T> 类
- 🔖 PCA<TSelf> 类
- 🔖 TSNE<T> 类
- 🔖 距离度量类
-
📒 信号处理模块
-
📒 数值模块
-
📒 统计模块
- 🔖 基础统计函数
- 🔖 高级统计函数
- 🔖 稳健统计 / RunningMoments
- 🔖 其它统计函数
- 🔖 分布相关函数
- 🔖 时间序列分析
- 🔖 IComparable 扩展
- 🔖 ExtremeValueFinder
- 🔖 INumber 扩展
-
📒 FFTW 扩展
-
📒 示例