Doug wrote this AMR test code Pat modified to use the Viterbi base class.
| 131 | // Doug wrote this AMR test code |
| 132 | // Pat modified to use the Viterbi base class. |
| 133 | void testEncodeDecode(const char *label, ViterbiBase *coder, unsigned frameSize, unsigned iRate, unsigned order, bool debug) |
| 134 | { |
| 135 | const bool isAMR = false; |
| 136 | const unsigned trials = 10; |
| 137 | cout << endl; |
| 138 | if (debug) cout << label << endl; |
| 139 | BitVector v1 = randomBitVector(frameSize); |
| 140 | if (debug) cout << "v1 " << v1 << endl; |
| 141 | int resultsize; |
| 142 | if (isAMR) { |
| 143 | resultsize = iRate*frameSize+iRate*order; |
| 144 | } else { |
| 145 | resultsize = iRate*frameSize; |
| 146 | } |
| 147 | BitVector v2(resultsize); |
| 148 | |
| 149 | |
| 150 | cout << LOGVAR(v1.size()) <<LOGVAR(v2.size()) << endl; |
| 151 | coder->encode(v1,v2); |
| 152 | if (debug) cout << "v2 " << v2 << endl; |
| 153 | int bec; |
| 154 | unsigned bitErrors; |
| 155 | |
| 156 | for (float badness = 0.0; badness <= 1.0; badness += 0.1) |
| 157 | for (int perr = 0; perr <= 50; perr += 10) { |
| 158 | int errsOut = 0; |
| 159 | int errsIn = 0; |
| 160 | // multiple trials smooths out the weirdnesses due to unfortunate positioning of noisy bits |
| 161 | for (unsigned trial = 0; trial < trials; trial++) { |
| 162 | SoftVector sv2(v2); |
| 163 | for (unsigned j = 0; j < sv2.size(); j++) { |
| 164 | if (random() % 100 < perr) { |
| 165 | // (pat) old test, this was not very good because 0.5 always maps to 1. |
| 166 | // sv2[j] = 0.5; |
| 167 | //sv2[j] = 1.0 - sv2[j]; |
| 168 | sv2[j] = sv2.bit(j) ? 1.0 - badness : badness; |
| 169 | errsIn++; |
| 170 | } |
| 171 | } |
| 172 | if (debug) cout << "n2 " << sv2 << endl; |
| 173 | BitVector v3(frameSize); |
| 174 | coder->decode(sv2,v3); |
| 175 | bec = coder->getBEC(); |
| 176 | if (debug) cout << "v3 " << v3 << endl; |
| 177 | for (unsigned j = 0; j < frameSize; j++) { |
| 178 | if (v1.bit(j) != v3.bit(j)) errsOut++; |
| 179 | } |
| 180 | |
| 181 | // Lets try re-encoding it and see what happens. |
| 182 | BitVector try2(resultsize); |
| 183 | coder->encode(v3,try2); |
| 184 | // The try should be equivalent to sv2? |
| 185 | bitErrors = 0; |
| 186 | for (unsigned k = 0; k < try2.size(); k++) { |
| 187 | if (try2[k] != sv2.bit(k)) bitErrors++; |
| 188 | } |
| 189 | } |
| 190 | int pbbo = 100 * errsOut / (frameSize * trials); |