# template tile for Lab #7, Task #1 import numpy import waveforms as w # parameters that control the encoding sample_rate = 1e6 bits_per_second = 30000 samples_per_bit = int(sample_rate/bits_per_second) # convert message bits into samples, then use samples # to modulate the amplitude of sinusoidal carrier def am_transmit(bits,samples_per_bit,fc): # use helper function to create a sampled_waveform by # converting each bit into samples_per_bit samples samples = w.symbols_to_samples(bits,samples_per_bit, sample_rate) # now multiply by sine wave of specified frequency return samples.modulate(hz=fc) # receive amplitude-modulated transmission: def am_receive(samples,fc,samples_per_bit): pass # your code here if __name__ == '__main__': message_size = 32 # a random binary message message = numpy.random.randint(2,size=message_size) # run transmitter fc = 125e3 # carrier frequency xmit_out = am_transmit(message,samples_per_bit,fc) # plot spectrum of transmitted message xmit_out.spectrum(title='spectrum of received samples', npoints=256000) # run receiver received = am_receive(xmit_out,fc,samples_per_bit) # report results print 'message: ',message print 'received:',received if not numpy.array_equal(message,received): print 'differences' else: print 'message received okay' # display the plots w.show()