# This is the template file for Lab #4, Task #2 import numpy import lab4 # compute even parity for a bit sequence def even_parity(bits): return sum(bits) % 2 # rect_decode -- correct errors in a rectangular block code (an SEC code) # arguments: # codeword -- numpy array of bits, whose length is equal to # nrows*ncols + nrows + ncols # (order of bits in array: all the data bits, # row-by-row, followed by the row parity bits, # followed by the column parity bits). # nrows -- integer, number of rows in rectangular block # ncols -- integer, number of columns in rectangular block # return value: # numpy array of size nrows*ncols of the most likely message bits def rect_decode(codeword,nrows,ncols): # Your code here pass # decode_stream -- decode a stream of blocks, each block encoded with # a rectangular parity code. Each block has nrows*ncols + nrows + ncols # bits when coded. The nrows + ncols parity bits for each block are # immeadiately following the block. def decode_stream(stream,nrows,ncols): # Your code here pass if __name__ == '__main__': # test your implementation # first tests correct decode with no errors # then tests correct decode with single error lab4.test_rect_decode(rect_decode) # then test stream decoding ability (not exhaustively) lab4.test_stream_decode(decode_stream) # when ready for checkoff, enable the next line. #lab4.checkoff(rect_decode,decode_stream,task='L4_2')