[-3,3] の範囲の値を持つ大きなデータ セットがあり、境界として 0 のハード リミットを使用しています。
56kHz の周波数で -3,3 から振動する場合、データは 1 のバイナリ値を持ちます。これが意味することは、N が通常 < 20 である N データ値ごとに、データが -3 から 3 に変化し、元に戻ることです。
データが常に 3 である場合、データは 0 のバイナリ値を持ちます (これは通常、400 以上のサンプルの長さを持続できます)。
データをバイナリカテゴリにグループ化することはできず、グループのサンプル数もわかりません。
サンプルデータ:
1.84 |
2.96 |
2.8 |
3.12 |
. | I want this to be grouped as a 0
. |
3.11 |_____
-3.42 |
-2.45 |
-1.49 |
3.12 |
2.99 | I want this to be grouped as a 1
1.97 |
-1.11 |
-2.33 |
. |
. | Keeps going until for N cycles
論理 HIGH 状態の間のサイクルは通常小さい (<20 サンプル)。
私がこれまでに持っているコード:
state = "X"
for i in range(0, len(data['input'])):
currentBinaryState = inputBinaryState(data['input'][i]); # Returns -3 or +3 appropriately
if(currentBinaryState != previousBinaryState):
# A cycle is very unlikely to last more than 250 samples
if y > 250 and currentBinaryState == "LOW": # Been low for a long time
if state == "_high":
groupedData['input'].append( ("HIGH", x) )
x = 0
state = "_low"
else:
# Is on carrier wave (logic 1)
if state == "_low":
# Just finished low
groupedData['input'].append( ("LOW", x) )
x = 0
state = "_high"
y = 0
明らかに、LOW グループは非常に小さいため、結果は期待どおりではありません。
[('HIGH', 600), ('LOW', 8), ('HIGH', 1168), ('LOW', 9), ('HIGH', 1168), ('LOW', 8), ('HIGH', 1168), ('LOW', 8), ('HIGH', 1168), ('LOW', 9), ('HIGH', 1168), ('LOW', 8), ('HIGH', 1168), ('LOW', 8), ('HIGH', 1168), ('LOW', 9)]
信号処理SAでこれを尋ねることができることは理解していますが、この問題はよりプログラミング指向であると考えました。質問がある場合は、問題を十分に説明したことを願っています。ありがとう。
実際のサンプル データへのリンクは次のとおりです。
https://drive.google.com/folderview?id=0ByJDNIfaTeEfemVjSU9hNkNpQ3c&usp=sharing
更新 1
1 文字の変数では正気を保てないため、コードを読みやすく更新しました。
previousBinaryState = "X"
x = 0
sinceLastChange = 0
previousGroup = inputBinaryState(data['input'][0])
lengthAssert = 0
for i in range(0, len(data['input'])):
currentBinaryState = inputBinaryState(data['input'][i]);
if(currentBinaryState != previousBinaryState): # Changed from -3 -> +3 or +3 -> -3
#print sinceLastChange
if sinceLastChange > 250 and previousGroup == "HIGH" and currentBinaryState == "LOW": # Finished LOW group
groupedData['input'].append( ("LOW", x) )
lengthAssert += x
x = 0
previousGroup = "LOW"
elif sinceLastChange > 20 and previousGroup == "LOW": # Finished HIGH group
groupedData['input'].append( ("HIGH", x) )
lengthAssert += x
x = 0
previousGroup = "HIGH"
sinceLastChange = 0
else:
sinceLastChange += 1
previousBinaryState = currentBinaryState
x += 1
サンプルデータの出力は次のとおりです。
8
7
8
7
7
596 <- Clearly a LOW group
7
8
7
8
7
7
8
7
8
7
7
8
7
8
7
7
8
7
8
.
.
.
問題は、HIGH グループが必要以上に長く続いていることです。
[('HIGH', 600), ('LOW', 1176), ('HIGH', 1177), ('LOW', 1176), ('HIGH', 1176), ('LOW', 1177), ('HIGH', 1176), ('LOW', 1176)]
- 作成されたグループは 8 つだけですが、プロットは明らかにそれ以上のものを示しています。グループは本来あるべきサイズの 2 倍の大きさに見えます。