# this is the template for Lab #3, Task #1 import numpy import matplotlib.pyplot as p import lab3 reload(lab3) p.ion() def sample_stats(samples,samples_per_bit=4,vth=0.5): # reshape array into samples_per_bit columns by as many # rows as we need. Each column represents one of the # sample times in a bit period. bins = numpy.reshape(samples,(-1,samples_per_bit)) # now compute statistics each column stats = [] for i in xrange(samples_per_bit): column = bins[:,i] dist = column - vth # subtract vth from each sample min_dist = ??? # Your code here avg_dist = ??? # Your code here avg_squared_dist = ??? # Your code here stats.append((min_dist,avg_dist,avg_squared_dist)) return stats # return collected statistics if __name__ == '__main__': stats = sample_stats(lab3.channel_data) for i in xrange(len(stats)): min,avg,avgsq = stats[i] print "sample %d: min_dist=%6.3f, avg_dist=%6.3f, " \ "avg_squared_dist=%6.3f" % (i,min,avg,avgsq) # when ready for checkoff, enable the following line #lab3.checkoff(sample_stats,'L3_1')