本文整理匯總了Python中receiver.Receiver.process方法的典型用法代碼示例。如果您正苦於以下問題:Python Receiver.process方法的具體用法?Python Receiver.process怎麽用?Python Receiver.process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類receiver.Receiver
的用法示例。
在下文中一共展示了Receiver.process方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import process [as 別名]
def run(config):
'''Primary Audiocom functionality.'''
# Create the preamble to pre-pend to the transmission
preamble = Preamble(config)
# Create the sources
sources = {}
for i in range(len(config.channels)):
frequency = config.channels[i]
source = Source(config, i)
print "Channel: %d Hz" % frequency
print "\n".join(["\t%s" % source])
sources[frequency] = source
# Create a sender for each source, so we can process the bits to
# get the modulated samples. We combine all of the modulated
# samples into a single array by adding them.
modulated_samples = []
for frequency in sources:
src = sources[frequency]
sender = Sender(frequency, preamble, config)
sender.set_source(src)
modulated_samples = util.add_arrays(sender.modulated_samples(), modulated_samples)
# Create the channel
if config.bypass:
channel = AbstractChannel(config.bypass_noise, config.bypass_h, config.bypass_lag)
else:
channel = AudioChannel(config)
# Transmit and receive data on the channel. The received samples
# (samples_rx) have not been processed in any way.
samples_rx = channel.xmit_and_recv(modulated_samples)
print 'Received', len(samples_rx), 'samples'
for frequency in config.channels:
r = Receiver(frequency, preamble, config)
try:
# Call the main receiver function. The returned array of bits
# EXCLUDES the preamble.
bits = r.process(samples_rx)
# Push into a Sink so we can convert back to a useful payload
# (this step will become more useful when we're transmitting
# files or images instead of just bit arrays)
src = sources[frequency]
sink = Sink(src)
received_payload = sink.process(bits)
print "Received %d data bits" % len(received_payload)
if src.type == Source.TEXT:
print "Received text was:", sink.received_text
if len(received_payload) > 0:
# Output BER
hd = util.hamming(received_payload, src.payload)
ber = float(hd)/len(received_payload)
print 'BER:', ber
else:
print 'Could not recover transmission.'
except Exception as e:
# In general, this is a fatal exception. But we'd still like
# to look at the graphs, so we'll continue with that output
print '*** ERROR: Could not detect preamble. ***'
print repr(e)
# Plot graphs if necessary
if config.graphs:
try:
len_demod = config.spb * (len(received_payload) + preamble.preamble_data_len())
except:
# If we didn't receive the payload, make a reasonable guess for the number of bits
# (won't work for filetype, where n_bits changes)
len_demod = config.spb * (config.n_bits + preamble.preamble_data_len())
if config.demod_type == Receiver.QUADRATURE:
filtered = r.graph_info.demod_samples
graphs.plot_sig_spectrum(samples_rx, filtered, "received samples", "filtered samples")
elif config.src_type == Source.U:
demod_samples = r.graph_info.demod_samples
plotrange = preamble.preamble_data_len()*config.spb
graphs.plot_samples(demod_samples[plotrange:len_demod], 'unit-step response', show=True)
else:
graphs.plot_graphs(r.graph_info.demod_samples[:len_demod], r.graph_info.hist_samples[:len_demod], config.spb, preamble)
示例2: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import process [as 別名]
def run(config):
'''Primary Audiocom functionality.'''
# Create the preamble to pre-pend to the transmission
preamble = Preamble(config)
# Create a source
source = Source(config)
frequency = config.channel
print "Channel: %d Hz" % frequency
print "\n".join(["\t%s" % source])
# Create the Sender for this Source. Process the bits to get
# modulated samples.
sender = Sender(frequency, preamble, config)
sender.set_source(source)
modulated_samples = sender.modulated_samples()
# Create the channel
if config.bypass:
channel = AbstractChannel(config.bypass_noise, config.bypass_h)
else:
channel = AudioChannel(config)
# Transmit and receive data on the channel. The received samples
# (samples_rx) have not been processed in any way.
samples_rx = channel.xmit_and_recv(modulated_samples)
print 'Received', len(samples_rx), 'samples'
r = Receiver(frequency, preamble, config)
try:
# Call the main receiver function. The returned array of bits
# EXCLUDES the preamble.
bits = r.process(samples_rx)
# Push into a Sink so we can convert back to a useful payload
# (this step will become more useful when we're transmitting
# files or images instead of just bit arrays)
sink = Sink(source)
received_payload = sink.process(bits)
print "Received %d data bits" % len(received_payload)
if len(received_payload) > 0:
# Output BER
hd = util.hamming(received_payload, source.payload)
ber = float(hd)/len(received_payload)
print 'BER:', ber
else:
print 'Could not recover transmission.'
except Exception as e:
# In general, this is a fatal exception. But we'd still like
# to look at the graphs, so we'll continue with that output
print '*** ERROR: Could not detect preamble. ***'
# Plot graphs if necessary
if config.graphs:
try:
len_demod = config.spb * (len(received_payload) + preamble.preamble_data_len())
except:
# If we didn't receive the payload, make a reasonable guess for the number of bits
len_demod = config.spb * (config.n_bits + preamble.preamble_data_len())
if config.src_type == Source.U:
demod_samples = r.graph_info.demod_samples
plotrange = preamble.preamble_data_len()*config.spb
graphs.plot_samples(demod_samples[plotrange:len_demod], 'unit-step response', show=True)
else:
graphs.plot_graphs(r.graph_info.demod_samples[:len_demod], r.graph_info.hist_samples[:len_demod], config.spb, preamble)