# lab1_3.py -- template for your Task #3 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(samples,samples_per_bit): """ Convert an array of voltage samples in to bits and return a numpy array of bits. """ 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") num_pixels = len(image) # Show the image p.figure() im1d.im1dshow(image, rows=64) # Turn the image into a sequence of bits bits = lab1.farray_to_bits(image) # encode 8-bit blocks encoded = lab1.encode_bits(bits) # Convert encoded image in to samples samples_per_bit = 8 samples = lab1.bits_to_samples(encoded,samples_per_bit) # Create a noise-free channel mychannel = channel.channel(channelid='0',noise=0.0, random_tails=0) # Send image noise-free, no delay channel rcvd_samples = mychannel(samples) # Your program to receive the bit stream rcvd_bits = receive(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,'L1_3')