简体   繁体   English

如何比较c#中两个波形的相似度?

[英]How to compare the similarity of two waveforms in c#?

I am trying to compare the similarity of two waveforms based on the visual aspect of the waveform and not how they sound.我试图根据波形的视觉方面而不是它们的声音来比较两个波形的相似性。
How would I be able to do this in c#?我怎么能在 c# 中做到这一点?

If the data of the waveforms are in a format such that the value at time = 0 can be indexed as waveform[0] and the next "frame" of the wave can be indexed as waveform[1] and the max value for a "frame" of a wave is 1 and the min value for a "frame" of a wave is -1, (and the two waves are the same length in units of "frames"), then I think this should work: (untested)如果波形数据的格式使得时间 = 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM