我正在尝试根据波形的视觉外观而非声音听起来来比较两个波形的相似性。
我将如何在C#中做到这一点?
最佳答案
如果波形数据的格式使得时间= 0时的值可以被索引为波形[0],而波的下一个“帧”可以被索引为波形[1],并且最大值为波浪的“框架”为1,波浪的“框架”的最小值为-1(并且两个波浪以“框架”为单位具有相同的长度),那么我认为这应该起作用:(未经测试)
//WaveForm 1 is w1 and WaveForm 2 is w2.
Stack<float> temp = new Stack<float>();
for(int i = 0; i < w1.Length; i++)
{
//differenceFactor is the variable that decides what difference means.
//at a value of 1, then a two waves with indexes -0.5 and 0.5 will be "100%"
//different. At a value of 0.5f then two waves with indexes -0.5 and 0.5 will be
//"50%" different. According to what I see, if differenceFactor > 1f then wave
//indexes greater than 1 unit apart are more than "100%" different, so probably don't
//do that.
float difference = Math.Abs(w1[i] - w2[i]);
temp.Push(((difference < differenceFactor) ? difference : differenceFactor) * 0.5f);
}
return temp.Average();
关于c# - 如何在C#中比较两个波形的相似性?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58127129/