2012-02-28 7 views
0

私は大きなフロート番号の配列を持っています。これらの数字は、セテンのピッチを表す。エラーのマージンを持つ数字のシーケンスを検出する

「類似した」番号のシーケンスを検出するにはどうすればよいですか。 「10未満」という違いを持っ​​て同じ数を見つけるのと同じように。

たとえば、私のリストは次のようになります。

0:1000 
1:2100 
2:2000 
3:440 
4:440 
5:430 
6:450 
7:440 
8:435 
9:445 
10:90 
11:200 
12:10 
13:50 
14:16 
15:880 
16:885 
16:880 
17:870 
18:875 

インデックス3から9までのエントリは、非常に似ています(最大10の差異)。 同様に、インデックス15〜18も非常に似ています。

どのようにしてこのような配列を処理し、同様の番号の各グループのインデックスを教えてくれた出力を得ることができますか?

EG:

Sequence 1 : Start index = 3 End Index=9 
Sequence 2 : Start index = 15 End Index=18 

編集1:

は、これを行うに私の最初の試みは、リストが移入されたとして、それを行うことでした。私は配列が5つのインデックスであった。処理されている次の数値が誤差の範囲内にあった場合は、この配列に追加します。配列がいっぱいになったとき、私は自分のシーケンスを持っていました。これは動作しますが、非常に柔軟性がありません。配列は配列の長さより長く続き、私はそれについて知りませんでした。

float dominant=bin*(THIS->samplerate/bufferCapacity); 



     float closestFloat=FREQ_WITHIN_RANGE; 

     concurrent_note.currentfrequency=dominant; 

     int index= concurrent_note.count; 

     float lastfreq=concurrent_note.frequencylist[index]; 

     float check=fabsf(lastfreq-concurrent_note.currentfrequency); 

     concurrent_note.frequencylist[index]=dominant; 



     if (check<=closestFloat) { 



      concurrent_note.currentfrequency=dominant; 

      concurrent_note.frequencylist[concurrent_note.count]=dominant; 

      concurrent_note.count++; 

      if (concurrent_note.count>=CONSECTUTIVE_SIMILAR_FREQ_THRESHOLD) { 

       //it is likely this is the same note 



       float averagenote=0; 

       for (int i=0; i<CONSECTUTIVE_SIMILAR_FREQ_THRESHOLD; i++) { 

        float note=concurrent_note.frequencylist[i]; 

        averagenote+=note; 

        concurrent_note.frequencylist[i]=0; 



       } 

       averagenote=averagenote/CONSECTUTIVE_SIMILAR_FREQ_THRESHOLD; 

       [THIS frequencyChangedWithValue:averagenote attime:(inTimeStamp->mSampleTime-fft.starttime) ]; 

       concurrent_note.count=0; 

      } 



     }else 

     { 

      concurrent_note.count=0; 

     } 
+0

あなたのリストが '{40、55、70}'だったらどうなりますか? –

+0

あなたはどんなアイデアを持っていましたか? – Rob

+0

私のビジネスはありませんが、サウンドと音楽の処理アルゴリズムは、通常、これを行うために自己相関を使用します:http://en.wikipedia.org/wiki/Autocorrelation – Diego

答えて

1

私はあなたのプログラムの構造は、私は擬似コードとして私の答えを提供してきましたされたものを言うことができないので:あなたは同様の要素のブロックの配列が残されると思い

var THRESHOLD = 10; 
var compareElement = getFirstElement(); 

var Array<Element> currentArrayOfSimilarElements; 
var Array<Array<Element>> arrayOfSimilarElements; 


for (int i = 1; i < list.length(); i++) //Start at element one 
{ 
    var element; 
    while(abs((element = list.objectAt(i)) - compareElement) < THRESHOLD) //While elements are within the threshold 
    { 
     currentArrayOfSimilarElements.add(element); //Add them to an array 
     i++; //And increase the index 
    } 
    compareElement = element; //We have a new object to compare to 
    arraysOfSimilarElements.add(currentArrayOfSimilarElements); //Add the block of similar elements we found 
    currentArrayOfSimilarElements.removeAll(); //And remove the elements from the block 
} 

[ 
    [440, 440, 430, 450, 440, 435, 445], 
    [880, 885, 880] 
] 
+0

このアイデアをありがとう。私はそれが私のためにどのように機能するかを見ていきます。 – dubbeat

関連する問題