def testblockLPC(signal, blocksize, numcoef, ideal=False, compress=False, lookback=True, showplot=True, bitdepth=1): #Set up receiver recv = Receiver(lookback=lookback) e_complete = zeros(0) #Process blocks for i in range(len(signal) / blocksize): #find LPC coefficients a = levinson(signal[i * blocksize:(i + 1) * blocksize], numcoef, False) #build error e = zeros(blocksize) if ideal == True: if i == 0 or recv.lookback == False: e = idealError(signal[i * blocksize:(i + 1) * blocksize], a, zeros(len(a))) else: e = idealError(signal[i * blocksize:(i + 1) * blocksize], a, signal[i * blocksize - len(a):i * blocksize]) if compress == True: temp_e = compressError(e, bitdepth) temp_e = shiftCompressedError(temp_e, bitdepth) e = scaleRMS(e, temp_e) else: classification = classify(signal[i * blocksize:(i + 1) * blocksize]) classification[1].sort() if classification[0] or True: for i in range(len(e)): # for p in classification[1]: if i % 60 == 0: e[i] = 1 else: e = randn(len(e)) # e = e*classification[2] e_complete = append(e_complete, e) #Xmit and rebuild recv.receiveIdeal(e, a) #complete the transmission recv.hangUp() if showplot == True: #Plot results subplot(3, 1, 1) title("Signal Reconstruction with Impulse Train", size=20) plot(signal, label="Input Signal", lw=2) legend() subplot(3, 1, 2) plot(e_complete, label="Excitation Signal", lw=2) legend() subplot(3, 1, 3) plot(recv.output, label="Decoded Signal", lw=2) # ylim([-5, 5]) legend() show() return recv.output
import random from receiver import Receiver # tests the receiver a = [] e = [] rec = Receiver() for i in range(25): for j in range(10): a.append(random.randint(1, 100)) e.append(random.randint(1, 100)) print "sending: %r" % i rec.receiveIdeal(e, a) e = [] a = [] rec.hangUp()
import random from receiver import Receiver # tests the receiver a = [] e = [] rec = Receiver() for i in range(25): for j in range(10): a.append(random.randint(1, 100)) e.append(random.randint(1, 100)) print "sending: %r" % i rec.receiveIdeal(e, a) e = [] a = [] rec.hangUp()
def testblockLPC(signal, blocksize, numcoef, ideal=False, compress=False, lookback = True, showplot=True, bitdepth=1): #Set up receiver recv = Receiver(lookback = lookback) e_complete = zeros(0) #Process blocks for i in range(len(signal)/blocksize): #find LPC coefficients a = levinson(signal[i*blocksize:(i+1)*blocksize], numcoef, False) #build error e = zeros(blocksize) if ideal == True: if i == 0 or recv.lookback == False: e = idealError(signal[i*blocksize:(i+1)*blocksize], a, zeros(len(a))) else: e = idealError(signal[i*blocksize:(i+1)*blocksize], a, signal[i*blocksize-len(a):i*blocksize]) if compress == True: temp_e = compressError(e, bitdepth) temp_e = shiftCompressedError(temp_e, bitdepth) e = scaleRMS(e, temp_e) else: classification = classify(signal[i*blocksize:(i+1)*blocksize]) classification[1].sort() if classification[0] or True: for i in range(len(e)): # for p in classification[1]: if i%60 == 0: e[i] = 1 else: e = randn(len(e)) # e = e*classification[2] e_complete = append(e_complete, e) #Xmit and rebuild recv.receiveIdeal(e, a) #complete the transmission recv.hangUp() if showplot == True: #Plot results subplot(3, 1, 1) title("Signal Reconstruction with Impulse Train", size=20) plot(signal, label="Input Signal", lw=2) legend() subplot(3, 1, 2) plot(e_complete, label="Excitation Signal", lw=2) legend() subplot(3, 1, 3) plot(recv.output, label="Decoded Signal", lw=2) # ylim([-5, 5]) legend() show() return recv.output