Пример #1
0
def main(k, ber, nerr, ITERATION=10):
	"testbench of combinational DECTED BCH" 

	# m = int(math.ceil(math.log(k, 2)) ) + 1 # DEBUG 
	# r = m*2 
	
	miscorr = 0 
	
	# -----------------------------END OF INIT --------------------------

	for i in range(ITERATION):
		# ----------ENCODER PART --------------------

		info = CreateMessage(k) 
		vec2hex = lambda v:hex(int(''.join(map(str,v)),2)) 
		enc = encoder(info, k)  #use TED BCH 
		print 'data_in:  ', info 
		print 'in_data HEX : ', vec2hex(info) 
		print 'encoded codeword: ',enc, 'length: ', len(enc) 
		print 'encoded HEX: ', vec2hex(enc) 
		
		# ------------NOISE/POLLUTION -------------------

		received = noise( enc, ber, nerr ) 
		err_vector = [x^y for x,y in izip(received, enc)] 
		err_location = np.nonzero(np.array(err_vector))[0].astype('int')  
		print 'received code: ', received
		print 'received code HEX: ', vec2hex(received) 
		print 'error pattern: ', err_vector  
		print 'number of errors = ', sum(err_vector), '; err_locator: ', err_location 


		# -------------- DECODER PART --------------------
		out_code,status = decoder( received, k)  


		if out_code[-k:] == info:
			print 'clean readout !!!'
		elif out_code[-k:] != info and status == 1: 
			miscorr += 1 
			print 'mis-correction!' 
		else:
			print 'detected 3+ errors, ' 
		
		print '-------------------- NEXT -----------------'

	print 'Total miscorrections = ', miscorr 
Пример #2
0
def main(r, k, ber, nerr, ITERATION=10):
	"testbench of CRC-r " 

	 
	
	detect_fail = 0
	
	# -----------------------------END OF INIT --------------------------

	for i in range(ITERATION):
		# ----------ENCODER PART --------------------

		info = CreateMessage(k) 
		vec2hex = lambda v:hex(int(''.join(map(str,v)),2)) 
		enc = crcEncoder(r, k, info)  
		print 'data_in:  ', info 
		print 'in_data HEX : ', vec2hex(info) 
		print 'encoded codeword: ',enc, 'parity: ', enc[:r]
		print 'encoded HEX: ', vec2hex(enc) 
		
		# ------------NOISE/POLLUTION -------------------

		received = noise( enc, ber, nerr ) 
		err_vector = [x^y for x,y in izip(received, enc)] 
		err_location = np.nonzero(np.array(err_vector))[0].astype('int')  
		print 'received code: ', received
		print 'received code HEX: ', vec2hex(received) 
		# print 'error pattern: ', err_vector  
		print 'number of errors = ', sum(err_vector), '; err_locator: ', err_location 


		# -------------- DECODER PART --------------------
		has_error = crcDecoder(r,k, received) # a boolean flag indicating error 
		if (sum(err_vector) and not has_error) or ( not sum(err_vector) and has_error ) :
			print 'fail to detect errors'
			detect_fail += 1  
		else:
			print 'success!!!' 


		

		
		print '-------------------- NEXT -----------------'

	print " detection failures = ", detect_fail 
Пример #3
0
def main(k, ber, nerr, ITERATION=10):
	"testbench of combinational BCH" 

	m = int(math.ceil(math.log(k, 2)) ) + 1 # DEBUG 
	r = m*2 
	
	
	
	# -----------------------------END OF INIT --------------------------

	for i in range(ITERATION):
		# ----------ENCODER PART --------------------

		info = CreateMessage(k) 
		vec2hex = lambda v:hex(int(''.join(map(str,v)),2)) 
		enc = encoder(info, k)  
		print 'data_in:  ', info 
		print 'in_data HEX : ', vec2hex(info) 
		print 'encoded codeword: ',enc, 'parity: ', enc[:r]
		print 'encoded HEX: ', vec2hex(enc) 
		
		# ------------NOISE/POLLUTION -------------------

		received = noise( enc, ber, nerr ) 
		err_vector = [x^y for x,y in izip(received, enc)] 
		err_location = np.nonzero(np.array(err_vector))[0].astype('int')  
		print 'received code: ', received
		print 'received code HEX: ', vec2hex(received) 
		print 'error pattern: ', err_vector  
		print 'number of errors = ', sum(err_vector), '; err_locator: ', err_location 


		# -------------- DECODER PART --------------------
		out_code = decoder( received, k) 

		if out_code[-k:] == info:
			print 'clean readout !!!'
		else:
			print 'false readout ...'
		
		print '-------------------- NEXT -----------------'