Skip to content

Commit d21539e

Browse files
committed
getMinDistancePath function | find min graph distances used this function to refine and remove large distances
1 parent da97f83 commit d21539e

1 file changed

Lines changed: 123 additions & 27 deletions

File tree

decoder.cpp

Lines changed: 123 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*
55
// No. of state check
66
We have used unsigned __int8 data type value in this simulation,
7-
it is obvious that it cannot be checked more than 4 times
7+
it is obvious that it cannot be checked more than 4 times
88
(with 8 bits, 4 bits can be decoded).
99
*/
1010
#define MAX_STATE_CEHCK 4
@@ -18,8 +18,9 @@ decoder::decoder() {
1818

1919
unsigned __int8 decoder::decode(unsigned __int8 recv) {
2020
std::cout << "decoder : " << std::bitset<8>(recv) << std::endl;
21-
node* n = graphTracer(0, recv, 1);
22-
printStates(n);
21+
//node* n = graphTracer(0, recv, 1);
22+
node* n = getMinDistancePaths(0, recv, 1);
23+
//printStates(n);
2324
/*for (int i = 1; n->getNextFirstStateNode() != nullptr; i++) {
2425
std::cout << "i : " << i << " | " << std::bitset<8>(n->getNextFirstStateNodeDistance()&0x03) << std::endl;
2526
std::cout << "i : " << i << " | " << std::bitset<8>(n->getNextScondStateNodeDistance() & 0x03) << std::endl;
@@ -29,7 +30,7 @@ unsigned __int8 decoder::decode(unsigned __int8 recv) {
2930
}
3031

3132
void decoder::printStates(node* n) {
32-
if (n->getNextFirstStateNode() == nullptr) {
33+
if (n->getNextFirstStateNode() == nullptr || n->getNextScondStateNode() == nullptr) {
3334
return;
3435
}
3536
std::cout << "state : " << std::bitset<8>(n->getState()) << std::endl;
@@ -41,50 +42,145 @@ void decoder::printStates(node* n) {
4142
this->printStates(n->getNextScondStateNode());
4243
}
4344

44-
node* decoder::graphTracer(unsigned __int8 state, unsigned __int8 data, unsigned __int8 level){
45+
node* decoder::getMinDistancePaths(unsigned __int8 state, unsigned __int8 data, unsigned __int8 level) {
4546
// return point | break point of recursive loop
4647
if (level == MAX_STATE_CEHCK + 2) {
4748
return nullptr;
4849
}
4950

51+
// data shifter : shift in each level
52+
__int8 shiftVal = 0;
53+
switch (level) {
54+
case 1:
55+
shiftVal = 6;
56+
break;
57+
case 2:
58+
shiftVal = 4;
59+
break;
60+
case 3:
61+
shiftVal = 2;
62+
break;
63+
case 4:
64+
shiftVal = 0;
65+
break;
66+
default:
67+
shiftVal = 0;
68+
break;
69+
}
70+
71+
5072
// set next states value
5173
// -1 == null value | initial value
5274
unsigned __int8 nextFirstState = -1,
5375
nextFirstStateIO = -1,
5476
nextScondState = -1,
5577
nextScondStateIO = -1;
5678

57-
switch (state){
58-
case 0:
59-
nextFirstState = 0;
60-
nextFirstStateIO = 0,
61-
nextScondState = 2,
62-
nextScondStateIO = 3;
79+
switch (state) {
80+
case 0:
81+
nextFirstState = 0;
82+
nextFirstStateIO = 0,
83+
nextScondState = 2,
84+
nextScondStateIO = 3;
85+
break;
86+
case 2:
87+
nextFirstState = 1;
88+
nextFirstStateIO = 1,
89+
nextScondState = 3,
90+
nextScondStateIO = 2;
91+
break;
92+
case 1:
93+
nextFirstState = 0;
94+
nextFirstStateIO = 3,
95+
nextScondState = 2,
96+
nextScondStateIO = 0;
97+
break;
98+
case 3:
99+
nextFirstState = 1;
100+
nextFirstStateIO = 2,
101+
nextScondState = 3,
102+
nextScondStateIO = 1;
103+
break;
104+
}
105+
node* stateNode = new node(state & 0x03);
106+
stateNode->setNextFirstStateNodeDistance(this->hammingDistance((data >> shiftVal) & 0x03, nextFirstStateIO));
107+
stateNode->setNextScondStateNodeDistance(this->hammingDistance((data >> shiftVal) & 0x03, nextScondStateIO));
108+
if (stateNode->getNextFirstStateNodeDistance() > stateNode->getNextScondStateNodeDistance()) {
109+
stateNode->setNextScondStateNode(*this->getMinDistancePaths(nextScondState, data, level + 1));
110+
}else if (stateNode->getNextFirstStateNodeDistance() < stateNode->getNextScondStateNodeDistance()) {
111+
stateNode->setNextFirstStateNode(*this->getMinDistancePaths(nextFirstState, data, level + 1));
112+
}else {
113+
stateNode->setNextFirstStateNode(*this->getMinDistancePaths(nextFirstState, data, level + 1));
114+
stateNode->setNextScondStateNode(*this->getMinDistancePaths(nextScondState, data, level + 1));
115+
}
116+
return stateNode;
117+
}
118+
119+
node* decoder::graphTracer(unsigned __int8 state, unsigned __int8 data, unsigned __int8 level) {
120+
// return point | break point of recursive loop
121+
if (level == MAX_STATE_CEHCK + 2) {
122+
return nullptr;
123+
}
124+
125+
// data shifter : shift in each level
126+
__int8 shiftVal = 0;
127+
switch (level){
128+
case 1:
129+
shiftVal = 6;
63130
break;
64131
case 2:
65-
nextFirstState = 1;
66-
nextFirstStateIO = 1,
67-
nextScondState = 3,
68-
nextScondStateIO = 2;
69-
break;
70-
case 1:
71-
nextFirstState = 0;
72-
nextFirstStateIO = 3,
73-
nextScondState = 2,
74-
nextScondStateIO = 0;
132+
shiftVal = 4;
75133
break;
76134
case 3:
77-
nextFirstState = 1;
78-
nextFirstStateIO = 2,
79-
nextScondState = 3,
80-
nextScondStateIO = 1;
135+
shiftVal = 2;
136+
break;
137+
case 4:
138+
shiftVal = 0;
139+
break;
140+
default:
141+
shiftVal = 0;
81142
break;
82143
}
144+
145+
146+
// set next states value
147+
// -1 == null value | initial value
148+
unsigned __int8 nextFirstState = -1,
149+
nextFirstStateIO = -1,
150+
nextScondState = -1,
151+
nextScondStateIO = -1;
152+
153+
switch (state) {
154+
case 0:
155+
nextFirstState = 0;
156+
nextFirstStateIO = 0,
157+
nextScondState = 2,
158+
nextScondStateIO = 3;
159+
break;
160+
case 2:
161+
nextFirstState = 1;
162+
nextFirstStateIO = 1,
163+
nextScondState = 3,
164+
nextScondStateIO = 2;
165+
break;
166+
case 1:
167+
nextFirstState = 0;
168+
nextFirstStateIO = 3,
169+
nextScondState = 2,
170+
nextScondStateIO = 0;
171+
break;
172+
case 3:
173+
nextFirstState = 1;
174+
nextFirstStateIO = 2,
175+
nextScondState = 3,
176+
nextScondStateIO = 1;
177+
break;
178+
}
83179
node* stateNode = new node(state & 0x03);
84180
stateNode->setNextFirstStateNode(*this->graphTracer(nextFirstState, data, level + 1));
85181
stateNode->setNextScondStateNode(*this->graphTracer(nextScondState, data, level + 1));
86-
stateNode->setNextFirstStateNodeDistance(this->hammingDistance(data,nextFirstStateIO));
87-
stateNode->setNextScondStateNodeDistance(this->hammingDistance(data,nextScondStateIO));
182+
stateNode->setNextFirstStateNodeDistance(this->hammingDistance((data >> shiftVal) & 0x03, nextFirstStateIO));
183+
stateNode->setNextScondStateNodeDistance(this->hammingDistance((data >> shiftVal) & 0x03, nextScondStateIO));
88184
return stateNode;
89185
}
90186

0 commit comments

Comments
 (0)