# lab1_4.py -- template for your Task #4 design file import numpy import matplotlib.pyplot as p import channel reload(channel) import lab1 reload(lab1) import im1d reload(im1d) p.ion() def receive_8b10b(samples,samples_per_bit): """ Convert an array of voltage samples transmitted by a 8b/10b encoder into a sequence of bits. Return the sequence of bits as a numpy array. """ return [] # testing code. Do it this way so we can import this file # and use its functions without also running the test code. if __name__ == '__main__': # Read in a .png image as array of greyscale values # with pixel values between 0.0 and 1.0 image = im1d.im1dread("mandrils") # Number of pixels in the image num_pixels = len(image) # Show the image p.figure() im1d.im1dshow(image, rows=64) # Turn the image in to a sequence of bits bits = lab1.farray_to_bits(image) # encode 8-bit blocks encoded = lab1.encode_bits_8b10b(bits) # Convert encoded image in to samples # The fractional value for samples_per_bit models clock # drift between the transmitter and receiver. In order to # work correctly, your code should resynchronize where it's # sampling each bit whenever it sees a transition. samples_per_bit=8.3 samples = lab1.bits_to_samples(encoded,samples_per_bit) # Create channel with noise and random delay and padding mychannel = channel.channel(channelid='0',noise=0.1, random_tails=300) # Send samples through channel with noise and random delay # and padding rcvd_samples = mychannel(samples) # Your program to receive the bit stream samples_per_bit=8 rcvd_bits = receive_8b10b(rcvd_samples, samples_per_bit) # Turn sequence of bits into an image rcvd_image = lab1.bits_to_farray(rcvd_bits) # Show the image if rcvd_image != []: p.figure() im1d.im1dshow(rcvd_image,rows=64) # enable the following line whey you're ready to submit # your code to the on-line server #lab1.checkoff(receive_8b10b,'L1_4')