Skip to content
Browse files

Further simplify reception

  • Loading branch information...
1 parent b1603d6 commit 83612faa79cbd68e61c6877c299f51ad6694f47f @keithw committed Nov 1, 2011
Showing with 17 additions and 11 deletions.
  1. +4 −6 library/au_receive.py
  2. +13 −5 library/au_sendreceive.py
View
10 library/au_receive.py
@@ -57,22 +57,20 @@ def __init__( self, center_frequency, bandwidth ):
self.tuner = Filter( center_frequency - bandwidth, center_frequency + bandwidth )
self.lowpass = Filter( 0, bandwidth )
- def demodulate( self, samples, carrier=0 ):
- sample_count = len( samples )
-
+ def demodulate( self, samples, carrier=0, offset=0 ):
# Tune in band around carrier frequency
samples = self.tuner( samples )
# Shift the modulated waveform back down to baseband
- SAMPLES = numpy.arange( 0, sample_count )
+ SAMPLES = numpy.arange( offset, offset + len( samples ) )
ARGS = SAMPLES * (CARRIER_CYCLES_PER_SECOND * 2.0 * math.pi / SAMPLES_PER_SECOND)
LOCAL_CARRIER = numpy.cos(ARGS) + complex(0,1) * numpy.sin(ARGS)
demodulated_samples = samples * LOCAL_CARRIER
# calculate average amplitude (DC amplitude)
- # we will use this for auto gain control
+ # we will use this for auto gain control if user has not supplied carrier phase
if carrier==0:
- carrier = sum( demodulated_samples ) / sample_count
+ carrier = sum( demodulated_samples ) / len( samples )
self.reference_carrier = carrier
View
18 library/au_sendreceive.py
@@ -66,11 +66,15 @@ def extract_payload( self, signal, payload_len ):
( preamble_start, payload_start ) = self.detect_preamble( signal )
# demodulate payload using carrier reference from preamble
- version2 = self.receiver.demodulate( signal[ preamble_start: ],
- carrier=self.receiver.reference_carrier )
+ slice_start = payload_start - 3*SECOND_CARRIER_LEN/4
+ slice_end = payload_start + payload_len
+ extracted_payload = self.receiver.demodulate( signal[ slice_start : slice_end ],
+ carrier=self.receiver.reference_carrier,
+ offset=slice_start )[ payload_start - slice_start: ]
- extracted_payload = version2[payload_start-preamble_start:payload_start-preamble_start+payload_len]
- assert( len(extracted_payload) == payload_len )
+ if len( extracted_payload ) != payload_len:
+ raise Exception( "WARNING: Only received %d of %d samples sent" % ( len(extracted_payload),
+ payload_len ) )
return extracted_payload
@@ -165,7 +169,11 @@ def detect_preamble( self, received_signal ):
# now that we've identified the payload, use one AGC setting for whole thing
# second, better demodulation
- preamble_decoded = self.receiver.demodulate( received_signal[ preamble_start : preamble_end ] )
+ slice_start = preamble_start - 3*SECOND_CARRIER_LEN/4
+ slice_end = preamble_end + 3*SECOND_CARRIER_LEN/4
+ preamble_decoded = self.receiver.demodulate( received_signal[ slice_start : slice_end ],
+ offset=slice_start )[ preamble_start - slice_start:
+ preamble_end - slice_start ]
# find REAL phase of preamble
expected_preamble = []

0 comments on commit 83612fa

Please sign in to comment.
Something went wrong with that request. Please try again.