std::complex<double> operator*(const bvec &a, const cvec &b) { it_assert_debug(a.size() == b.size(), "operator*(): sizes does not match"); std::complex<double> temp = 0; for (int i = 0;i < a.size();i++) {temp += (double)a(i) * b(i);} return temp; }
cvec operator+(const bvec &a, const cvec &b) { it_assert_debug(a.size() == b.size(), "operator+(): sizes does not match"); cvec temp = b; for (int i = 0;i < a.size();i++) {temp(i) += (double)a(i);} return temp; }
void binbuff::set_output(bvec yout) { if (yout.size() != symbol_size) { throw sci_exception("binbuff::set_output yout.size <> symbol_size ", symbol_size ); } y0 = yout; }
void Rec_Syst_Conv_Code::encode_tail(const bvec &input, bvec &tail, bmat &parity_bits) { int i, j, length = input.size(), target_state; parity_bits.set_size(length+m, n-1, false); tail.set_size(m, false); encoder_state = 0; for (i=0; i<length; i++) { for (j=0; j<(n-1); j++) { parity_bits(i,j) = output_parity(encoder_state,2*j+int(input(i))); } encoder_state = state_trans(encoder_state,int(input(i))); } // add tail of m=K-1 zeros for (i=0; i<m; i++) { target_state = (encoder_state<<1) & ((1<<m)-1); if (state_trans(encoder_state,0)==target_state) { tail(i) = bin(0); } else { tail(i) = bin(1); } for (j=0; j<(n-1); j++) { parity_bits(length+i,j) = output_parity(encoder_state,2*j+int(tail(i))); } encoder_state = target_state; } terminated = true; }
bool CRC_Code::decode(const bvec &coded_bits, bvec &out) const { out = coded_bits(0, coded_bits.size() - no_parity - 1); if (check_parity(coded_bits)) { return true; } else return false; }
/* Returns the number of errors between in1 and in2. */ double BERC::count_errors(const bvec &in1, const bvec &in2, int indelay, int inignorefirst, int inignorelast) { int countlength = std::min(in1.size(), in2.size()) - std::abs(indelay) - inignorefirst - inignorelast; int local_errors = 0; if (indelay >= 0) { for (int i = 0; i < countlength; i++) { if (in1[i + inignorefirst] != in2[i + inignorefirst + indelay]) { local_errors++; }//end if }//end for }else { for (int i = 0; i < countlength; i++) { if (in1[i + inignorefirst - indelay] != in2[i + inignorefirst]) { local_errors++; }//end if }//end for }//end if return local_errors; }
/* Cumulative error counter */ void BERC::count(const bvec &in1, const bvec &in2) { int countlength = std::min(in1.size(), in2.size()) - std::abs(delay) - ignorefirst - ignorelast; if (delay >= 0) { for (int i = 0; i < countlength; i++) { if (in1[i + ignorefirst] == in2[i + ignorefirst + delay]) { corrects++; }else { errors++; }//end if }//end for }else { for (int i = 0; i < countlength; i++) { if (in1[i + ignorefirst - delay] == in2[i + ignorefirst]) { corrects++; }else { errors++; }//end if }//end for }//end if }
void Rec_Syst_Conv_Code::encode(const bvec &input, bmat &parity_bits) { int i, j, length = input.size(); parity_bits.set_size(length, n-1, false); encoder_state = 0; for (i=0; i<length; i++) { for (j=0; j<(n-1); j++) { parity_bits(i,j) = output_parity(encoder_state,2*j+int(input(i))); } encoder_state = state_trans(encoder_state,int(input(i))); } terminated = false; }
// Not optimized for speed bool CRC_Code::check_parity(const bvec &coded_bits) const { int n = coded_bits.size(); bvec temp; if (reverse_parity) { temp = concat(coded_bits.left(n - no_parity), reverse(coded_bits.right(no_parity))); } else { temp = coded_bits; } for (int i = 0; i < temp.size() - polynomial.size() + 1; i++) { if (temp(i) == 1) { temp.set_subvector(i, temp(i, i + no_parity) + polynomial); } } if (temp(temp.size() - no_parity, temp.size() - 1) == zeros_b(no_parity)) return true; else return false; }
inline int lsr::get_length(void) {return memory.size();}