Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Variable carrier frequency!!

  • Loading branch information...
commit 96f257231b2ce9b8d9cf6e142ff279d374b9da66 1 parent d91f91f
@keithw authored
View
1  library/au_defs.py
@@ -4,7 +4,6 @@
FORMAT = pyaudio.paFloat32
CHANNELS = 1
SAMPLES_PER_SECOND = 8000
-CARRIER_CYCLES_PER_SECOND = 2500
AMPLITUDE = 0.5
DC = 0.5
View
5 library/au_receive.py
@@ -52,6 +52,8 @@ def receive( self, num_samples, stream, samples_per_chunk ):
return self.demodulate( raw_receive( num_samples, stream, samples_per_chunk ) )
def __init__( self, center_frequency, bandwidth ):
+ self.carrier_freq = center_frequency
+
self.tuner = Filter( center_frequency - bandwidth, center_frequency + bandwidth )
self.lowpass = Filter( 0, bandwidth )
@@ -65,7 +67,7 @@ def demodulate( self, samples ):
# By multiplying by a complex exponential
# First, we make the complex exponential (the local carrier)
- args = numpy.arange(0,len(samples)) * CARRIER_CYCLES_PER_SECOND * 2 * math.pi / SAMPLES_PER_SECOND
+ args = numpy.arange(0,len(samples)) * self.carrier_freq * 2 * math.pi / SAMPLES_PER_SECOND
local_carrier = numpy.cos(args) + complex(0,1) * numpy.sin(args)
# Now, we shift down to baseband (and also up to 2x LOCAL_CARRIER)
@@ -86,4 +88,3 @@ def demodulate( self, samples ):
filtered_samples = self.lowpass( shifted_samples )
return filtered_samples
-
View
13 library/au_send.py
@@ -12,14 +12,6 @@
from au_filter import Filter
from au_defs import *
-TIME = 0 # seconds
-
-cachelen = SAMPLES_PER_SECOND
-COS_CACHE = [0] * cachelen
-for i in range( cachelen ):
- COS_CACHE[ i ] = math.cos( CARRIER_CYCLES_PER_SECOND * TIME * 2 * math.pi )
- TIME += 1.0 / SAMPLES_PER_SECOND
-
total_sample_count = 0
lowpass = Filter( 0, 500 )
@@ -44,8 +36,7 @@ def raw_send( chunks, stream ):
stream.write( chunk )
# Send one chunk of I samples, modulated onto the carrier frequency
-def modulate_float( samples, samples_per_chunk ):
- global TIME
+def modulate_float( samples, carrier_freq, samples_per_chunk ):
global total_sample_count
global lowpass
@@ -58,7 +49,7 @@ def modulate_float( samples, samples_per_chunk ):
samples = lowpass( samples )
for s in samples:
- chunk_data[ chunk_number ] += struct.pack( 'f', ((s * AMPLITUDE) + DC) * COS_CACHE[ total_sample_count % cachelen ] )
+ chunk_data[ chunk_number ] += struct.pack( 'f', ((s * AMPLITUDE) + DC) * math.cos( total_sample_count * 2 * math.pi * carrier_freq / SAMPLES_PER_SECOND ) )
total_sample_count += 1
sample_count += 1
View
16 library/au_sendreceive.py
@@ -43,7 +43,7 @@ def test( x, y ):
return self.i - match_length
class channel:
- def prepend_preamble( self, samples ):
+ def send_voltage_samples( self, samples ):
# prepare premable
signal = [-1] * 16384 + [0] * 16384
for i in range( PREAMBLE_BITS / 2 ):
@@ -57,7 +57,7 @@ def prepend_preamble( self, samples ):
signal.extend( [-1] * 32768 )
# prepare modulated output
- samples_out = modulate_float( signal, SAMPLES_PER_CHUNK )
+ samples_out = modulate_float( signal, self.carrier_freq, SAMPLES_PER_CHUNK )
return samples_out
@@ -85,7 +85,7 @@ def __call__( self, samples ):
output = True,
frames_per_buffer = SAMPLES_PER_CHUNK)
- samples_out = self.prepend_preamble( samples )
+ samples_out = self.send_voltage_samples( samples )
samples_in = []
# send output and collect input
@@ -101,20 +101,20 @@ def __call__( self, samples ):
return self.extract_payload( samples_all, len( samples ) )
- def __init__( self, carrier, bandwidth ):
+ def __init__( self, carrier_freq, bandwidth ):
self.id = "Audio"
self.p = pyaudio.PyAudio()
- self.carrier = carrier
+ self.carrier_freq = carrier_freq
self.bandwidth = bandwidth
- self.receiver = au_receive.Receiver( carrier, bandwidth )
+ self.receiver = au_receive.Receiver( carrier_freq, bandwidth )
self.one = [1] * PREAMBLE_BIT_LEN
self.zero = [-1] * PREAMBLE_BIT_LEN
- self.f1 = Filter( self.carrier - self.bandwidth, self.carrier + self.bandwidth )
+ self.f1 = Filter( self.carrier_freq - self.bandwidth, self.carrier_freq + self.bandwidth )
self.f2 = Filter( 0, self.bandwidth )
def detect_preamble( self, received_signal ):
@@ -215,6 +215,6 @@ def detect_preamble( self, received_signal ):
return ( preamble_start, payload_start )
def dmd( self, samples ):
- args = numpy.arange(0,len(samples)) * CARRIER_CYCLES_PER_SECOND * 2 * math.pi / SAMPLES_PER_SECOND
+ args = numpy.arange(0,len(samples)) * self.carrier_freq * 2 * math.pi / SAMPLES_PER_SECOND
ds = self.f1( samples ) * (numpy.cos(args) + complex(0,1) * numpy.sin(args))
return self.f2( [x.real for x in (len(samples)*ds/sum(ds) - 1) * DC/AMPLITUDE] )
View
4 response/PS5_1.py
@@ -26,13 +26,13 @@ def unit_step_response(channel,max_length=100):
"""
# step = [0]*(max_length*3/2) + [-1]*(max_length/2) + [1]*(max_length) + [-1]*(max_length/2) + [1]*(max_length/2)
- step = [0] * 100 + [1] * 100 + [-.5] * 50
+ step = [0] * 100 + [1] * 100 + [-1] * 100 + [0.5] * 100 + [-0.5] * 100
step_response = channel(step)
# return step_response[max_length/2 - 128: max_length/2 + 128]
return step_response
if __name__ == '__main__':
- channel = au_sendreceive.channel( 2500, 500 )
+ channel = au_sendreceive.channel( 1500, 500 )
# plot the unit-sample response of our three virtual channels
# PS5_tests.plot_USR(unit_step_response(channel0),'0')
Please sign in to comment.
Something went wrong with that request. Please try again.