Esempio n. 1
0
    def __init__(self, filename, samplerate=48000, mode='r'):

        self.samplerate = samplerate
        self.carrier = 1450 * 11
        self.symrate = 960 * 2
        self.symlen = self.samplerate / self.symrate
        w = wave.open(filename, mode + "b")
        if mode == 'w':
            snr = 10  #dB
            self.att = 10**(snr / 20.0)

            w.setnchannels(1)
            w.setframerate(samplerate)
            w.setsampwidth(2)
        elif mode == 'r':
            assert (w.getnchannels() == 1)
            assert (w.getframerate() == samplerate)
            assert (w.getsampwidth() == 2)
            invsqr2 = 1.0 / sqrt(2.0)
            cutoff = self.symrate
            self.iir_i = Biquad(Biquad.LOWPASS, cutoff, samplerate, invsqr2)
            self.iir_q = Biquad(Biquad.LOWPASS, cutoff, samplerate, invsqr2)
            self.curr_phase = 0
            self.phase_max = self.symlen
        else:
            assert (0)

        self.w = w

        self.t = 0
        self.bit_per_symbol = 3
        symbols = 1 << self.bit_per_symbol
        self.amps = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1),
                     (0, -1), (1, -1)]
        self.curr_preamble_p = 0
        self.preamble_p = [IqPoint(16) for i in range(2)]
        self.preamble_ref = [1, 4]

        #00110000 11000011 00001100
        self.preamble = "\x30\xC3\x0C" * 8 + "\x30\xC3\x0F"
        self.preamble_sync = 0
        self.sync = 0
        self.edge_lock = 0
        self.a = Sma(8)
        self.b = Sma(8)
        self.a.add(0)
        self.b.add(0)
        self.symbols = symbols
        self.carry = 0
        self.carry_len = 0
Esempio n. 2
0
cf = 1
dev = 2000
start_f = cf - dev
end_f = cf + dev
modi = 0

pll_integral = 0
pll_lock = 0
old_ref = 0
pll_cf = 2000
pll_loop_gain = 8
ref_sig = 0

invsqr2 = 1.0 / math.sqrt(2.0)

output_lowpass = Biquad(Biquad.LOWPASS, 20, sample_rate, invsqr2)

fa = []
da = []
tSig = []
rSig = []
xaxis = []

dur = 4

for n in range(int(sample_rate * dur)):
    t = n / sample_rate
    print t

    # BEGIN test signal block
    sweep_freq = ntrp(t, 0, dur, start_f, end_f)
Esempio n. 3
0
def getLpfFilter(cutoff, Q = Q_BUTTERWORTH):
    return Biquad(Biquad.LOWPASS, cutoff, SAMPLING_RATE, Q)
Esempio n. 4
0
def getNotchFilter(centerFreq, cutoff):
    Q = filterGetNotchQ(centerFreq, cutoff)
    result = Biquad(Biquad.NOTCH, centerFreq, SAMPLING_RATE, Q)
    return result
Esempio n. 5
0
sample_rate = 40000.0 # sampling frequency

cf = 1000

pll_integral = 0
old_ref = 0
pll_cf = 1000
pll_loop_gain = 0.00003
ref_sig = 0

invsqr2 = 1.0 / sqrt(2.0)

cutoff = .06 # Units Hz

loop_lowpass = Biquad(Biquad.LOWPASS,cutoff,sample_rate,invsqr2)

lock_lowpass = Biquad(Biquad.LOWPASS,cutoff,sample_rate,invsqr2)

ta = []
da = []
db = []

noise_level = 100 # +40 db

dur = 300 # very long run time

for n in range(int(sample_rate) * dur):
  t = n / sample_rate

  # BEGIN test signal block
cf = 2000
dev = 140
start_f = cf - dev
end_f = cf + dev
modi = 0

pll_integral = 0
old_ref = 0
pll_cf = 2000
pll_loop_gain = .05
ref_sig = 0

invsqr2 = 1.0 / sqrt(2.0)

loop_lowpass = Biquad(Biquad.LOWPASS,100,sample_rate,invsqr2)

output_lowpass = Biquad(Biquad.LOWPASS,10,sample_rate,invsqr2)

lock_lowpass = Biquad(Biquad.LOWPASS,10,sample_rate,invsqr2)

fa = []
da = []
db = []
dc = []

noise_level = 1

dur = 4

for n in range(int(sample_rate * dur)):