def MQAM(v, M, Ts, T, itermG=False): # Geração do sinal MQAM """ v = mensagem de Entrada M = nº da modulação Ts = período por símbolo T = periodo da portadora """ print("Modulação Iniciada") modcpy = commod.QAMModem(M) a2 = modcpy.modulate(v) print(a2) qam_real = [] qam_img = [] for i in a2: qam_real += [i.real]*Ts qam_img += [i.imag]*Ts qam_real = np.array(qam_real) qam_img = np.array(qam_img) m = [] q = [] i = [] f, t = crr.Generic_Carrier(T) print(f"{f} , {t}") if itermG == True: plot_message(qam_real, qam_img) for k in range(0,len(qam_real)): yr=qam_real[k]*np.cos(2*np.pi*f*t) yim=qam_img[k]*np.sin(2*np.pi*f*t) y=[a + b for a, b in zip(yr, yim)] m = m+y q = q + list(yr) i = i + list(yim) c1 = np.cos(2*np.pi*f*t) print("Modulação Terminada") return np.array(m), np.array(q), np.array(i)
def De_MQAM_Entrelac_TH(signal, key, M, T, itermG=False): """ signal = sinal modulado M = nº da modulação key = chave de desentrelaçamento da constelação T = período do cada quadro """ modcpy = commod.QAMModem(M) msg = crr.CarrierDemodeQAMEntrelac(signal, T, modcpy, key, itermG) return msg
def get_modem(self) -> mod.Modem: """ Gets the modem that is going to be used for this particular WiFi simulation according to the MCS """ bits_per_symbol = [2, 4, 4, 16, 16, 64, 64, 64, 256, 256] if self.mcs <= 2: # BPSK for mcs 0 # QPSK for mcs 1 a 2 return mod.PSKModem(bits_per_symbol[self.mcs]) else: # Modem : QAMModem return mod.QAMModem(bits_per_symbol[self.mcs])
def __init__(self, modulation="4_QAM"): self.modulation = modulation if modulation == "4_QAM": self.bitsPerBaud = 2 self.nSymbols = 4 elif modulation == "8_QAM": self.bitsPerBaud = 3 self.nSymbols = 8 elif modulation == "16_QAM": self.bitsPerBaud = 4 self.nSymbols = 16 elif modulation == "64_QAM": self.bitsPerBaud = 6 self.nSymbols = 64 #self.baudRate = baudRate self.modem = modem.QAMModem(self.nSymbols)
def MQAM_Entrelac_TV(v, sz, M, T, itermG=False): # Geração do sinal MQAM Entrelaçado Tipo B (usando divisão vetorial de tamanho igual ao logaritmo do tamanho da mensagem) """ v = mensagem de Entrada M = nº da modulação T = periodo do quadro """ print("Entrelaçamento Iniciado") dec = "" bin_arr_x0 = [] lim = max2pow(np.log2(M)) # Execução do logarítimo para iteração if lim > 16: # (M <= 256) lim = 16 print("M = {}QAM".format(lim)) for i in range(0, len(v), int(lim)): # Divisão do vetor bin_arr_x0.append(np.array(v[i:i+int(lim)])) print(np.array(v)) print(len(v)) aux = np.transpose(np.array(bin_arr_x0)) # transposição do vetor print(aux) a2 = [] l1 = 0 print("Entrelaçamento Finalizado") print("Modulação Iniciada") modcpy = commod.QAMModem(M) # obtenção das partes reiais e imaginárias a partir da divisão da matriz transposta e conversão M-ária gradual for b in aux: # mapeamento dos bits d1 = modcpy.modulate(b) l1 = len(d1) for i in d1: a2.append(i) a2 = np.array(a2) qam_real = a2.real qam_img = a2.imag m = [] f, t = crr.Generic_Carrier(T) print(f"{f} , {t}") if itermG == True: plot_message(qam_real, qam_img) for k in range(0,len(qam_real)): yr=qam_real[k]*np.cos(2*np.pi*f*t) yim=qam_img[k]*np.sin(2*np.pi*f*t) y=[a + b for a, b in zip(yr, yim)] m = m + y c1 = np.cos(2*np.pi*f*t) print("Modulação Terminada") return np.array(m), l1, len(c1)
def get_modem(self) -> mod.Modem: """ Gets the modem that is going to be used for this particular WiFi simulation according to the MCS """ qpsks = [ 2, 4, 4, 16, 64, 64, 64, 256, 256 ] if self.mcs == 0: # BPSK return mod.PSKModem(2) else: # Modem : QPSK return mod.QAMModem(qpsks[self.mcs])
def MQPSK(v, M, T, itermG=False): #Double-MPSK geração de 2 sinais MPSK: 1 em fase e 1 em quadratura """ v = mensagem de Entrada M = nº da modulação T = periodo do quadro """ print("Modulação Iniciada") dec = "" print(np.array(v)) modcpy = commod.QAMModem(M) a2 = modcpy.modulate(v) print(np.array(a2)) if itermG == True: plot_message(np.array(a2).real, np.array(a2).imag) s = [] # Ajuste do MPSK gs = pskf.cosAdjust(np.array(a2).real, T, M) + pskf.sinAdjust(np.array(a2).imag, T, M) print(np.array(gs)) f, t = crr.Generic_Carrier(T) c1 = np.cos(2*np.pi*f*t) print("Modulação Terminada") return np.array(gs), a2.real, a2.imag
def MPPM(v, M, T, itermG=False): print("Modulação Iniciada") modcpy = commod.QAMModem(M) a2 = modcpy.modulate(v) qam_real = a2.real qam_img = a2.imag m = [] q = [] i = [] f, t = crr.Generic_Carrier(T) print(f"{f} , {t}") if itermG == True: plot_message(qam_real, qam_img) for k in range(0,len(qam_real)): yr=qam_real[k]*np.array([1]*int(t)) yim=qam_img[k]*np.array([1]*int(t)) y=[a + b for a, b in zip(yr, yim)] m = m + y q = q + list(yr) i = i + list(yim) print("Modulação Finalizada") return np.array(m), np.array(q), np.array(i)
def signalGeneration(SIGNAL_NUM=50000): ''' init params ---------------------- params: X: signals with I and Q series Y: labels with the 5 classes, 0-1 5-dim vectors Z: SNRs classes = ['BPSK', 'QPSK', '8PSK', 'QAM16', 'QAM64'] ''' X = np.zeros([SIGNAL_NUM, 2, SYMBOL_NUM * SYMBOL_RATE]) Y = np.zeros([SIGNAL_NUM, 5]) Z = np.zeros([SIGNAL_NUM]) #X2 = np.zeros([SIGNAL_NUM, 2, SYMBOL_NUM*SYMBOL_RATE]) for iterator in xrange(SIGNAL_NUM): pid = os.getpid() print('pid:%d, iterator:%d' % (pid, iterator)) ''' generate 5 modulationTypes randomly generate #SYMBOL_NUM# symbols randomly construct constellation ''' modulationType = np.random.random_integers(1, 5, 1) label = np.zeros(5) label[modulationType - 1] = 1 Y[iterator] = label if modulationType == 1: '''BPSK''' inputSeries = np.random.random_integers(0, 1, SYMBOL_NUM * CONST_BPSK) modulationSeries = modulation.PSKModem(2).modulate(inputSeries) modulationSeries = interpolation(modulationSeries, SYMBOL_RATE) elif modulationType == 2: '''QPSK''' inputSeries = np.random.random_integers(0, 1, SYMBOL_NUM * CONST_QPSK) modulationSeries = modulation.PSKModem(4).modulate(inputSeries) modulationSeries = interpolation(modulationSeries, SYMBOL_RATE) elif modulationType == 3: '''8PSK''' inputSeries = np.random.random_integers(0, 1, SYMBOL_NUM * CONST_8PSK) modulationSeries = modulation.PSKModem(8).modulate(inputSeries) modulationSeries = interpolation(modulationSeries, SYMBOL_RATE) elif modulationType == 4: '''QAM16''' inputSeries = np.random.random_integers(0, 1, SYMBOL_NUM * CONST_QAM16) modulationSeries = modulation.QAMModem(16).modulate(inputSeries) modulationSeries = interpolation(modulationSeries, SYMBOL_RATE) elif modulationType == 5: '''QAM64''' inputSeries = np.random.random_integers(0, 1, SYMBOL_NUM * CONST_QAM64) modulationSeries = modulation.QAMModem(64).modulate(inputSeries) modulationSeries = interpolation(modulationSeries, SYMBOL_RATE) else: print 'incorrect modulationType' break '''use RRC''' [t, hRRC] = cp.filters.rrcosfilter(33, 0.4, 1, SYMBOL_RATE) signal = np.convolve(modulationSeries, hRRC, mode='same') '''add phrase, freq offset''' OFFSET_F = 0.01 OFFSET_PH = float(np.random.randint(0, 314)) / 100 signal = cp.add_frequency_offset( signal, SYMBOL_RATE, OFFSET_F * float(np.random.randint(8, 15)) / 10) signal = signal * np.exp(-OFFSET_PH * 1j) '''channel''' '''rayleigh channel''' H_CHANNEL = [ 0.342997170285018 + 2.75097576175635j, 0.342995668431465 + 2.75097418548155j, 0.342991162874393 + 2.75096945665969j, 0.342983653624566 + 2.75096157529839j, 0.342973140699920 + 2.75095054141035j, 0.342959624125568 + 2.75093635501332j, 0.342943103933798 + 2.75091901613016j, 0.342923580164072 + 2.75089852478880j, 0.342901052863027 + 2.75087488102222j, 0.342875522084475 + 2.75084808486853j ] signal = np.convolve(signal, H_CHANNEL, mode='same') '''noise by quantitative SNR''' snr = SNRs[np.random.randint(0, len(SNRs))] Z[iterator] = snr #signal2 = signal signal = awgn(signal, snr) '''regulization''' length = np.zeros([len(signal)]) for i in xrange(len(signal)): length[i] = np.sqrt( np.power(np.imag(signal[i]), 2) + np.power(np.real(signal[i]), 2)) maxLen = length[np.where(length == np.max(length))] signal = signal / maxLen[0] '''reconstruction''' signalI = np.real(signal) signalQ = np.imag(signal) X[iterator][0] = signalI X[iterator][1] = signalQ #X2[iterator][0] = np.real(signal2) #X2[iterator][1] = np.imag(signal2) return [X, Y, Z]
tb_depth) num_bit_errors = util.hamming_dist(message_bits, decoded_bits[:len(message_bits)]) if num_bit_errors != 0: print(num_bit_errors, "Bit Errors found!") elif i == 9: print("No Bit Errors :)") # ================================================================================================== # Complete example using Commpy features and compare hard and soft demodulation. Example with code 1 # ================================================================================================== # Modem : QPSK modem = mod.QAMModem(4) # AWGN channel channels = chan.SISOFlatChannel(None, (1 + 0j, 0j)) # SNR range to test SNRs = np.arange(0, 6) + 10 * math.log10(modem.num_bits_symbol) # Modulation function def modulate(bits): return modem.modulate(cc.conv_encode(bits, trellis1, 'cont')) # Receiver function (no process required as there are no fading) def receiver_hard(y, h, constellation, noise_var):