File: ber.py

package info (click to toggle)
gr-dab 0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,272 kB
  • sloc: python: 14,976; cpp: 6,738; ansic: 547; makefile: 19; sh: 11
file content (17 lines) | stat: -rw-r--r-- 427 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def bits_set(x):
	bits = 0
	for i in range(0,8):
		if (x & (1<<i))>0:
			bits += 1
	return bits

def find_ber(sent, received):
	assert(len(received)<=len(sent))
	if len(received) < len(sent)/2:
		print "frame detection error, more than half of the frames were lost!"
		return 0.5
	errors = 0
	for i in range(0,len(received)):
		errors += bits_set(sent[i] ^ received[i]) # ^ is xor
	return float(errors)/float(8*len(received))