def transceive_si_s(self, n): offset_n = n + 2 * (self.h_si_len - 1) # 遅延を取る為に多く作っておく # 送信信号 self.d = np.random.choice([0, 1], offset_n) self.x = m.modulate_qpsk(self.d) # 希望信号 self.d_s = np.random.choice([0, 1], offset_n) self.s = m.modulate_qpsk(self.d_s) # 送信側非線形 if self.tx_iqi == True: self.x_iq = m.iq_imbalance(self.x, self.gamma, self.phi) else: self.x_iq = self.x if self.pa == True: self.x_pa = m.sspa_rapp_ibo(self.x_iq, self.PA_IBO_dB, self.PA_rho) else: self.x_pa = self.x_iq # 通信路 # [[x[n], x[n-1]], x[x-1], x[n-1]]のように通信路の数に合わせる chanels_x_pa = np.array([ self.x_pa[i:i + self.h_si_len] for i in range(self.x_pa.size - self.h_si_len + 1) ]) chanels_y_si = self.h_si * chanels_x_pa y_si = np.sum(chanels_y_si, axis=1) # [[x[n], x[n-1]], x[x-1], x[n-1]]のように通信路の数に合わせる chanels_s = np.array([ self.s[i:i + self.h_s_len] for i in range(self.s.size - self.h_s_len + 1) ]) chanels_s = self.h_s * chanels_s y_s = np.sum(chanels_s, axis=1) r = y_si + y_s + m.awgn(y_si.shape, self.sigma) # 受信側非線形 if self.lna == True: y_lna = m.sspa_rapp(r, self.a_sat, self.LNA_rho).squeeze() else: y_lna = r if self.rx_iqi == True: y_iq = m.iq_imbalance(y_lna, self.gamma, self.phi) else: y_iq = y_lna self.y = y_iq
def set_lna_a_sat(self, n, LNA_IBO_dB): # TODO 調整する offset_n = n + 2 * (self.h_si_len - 1) # 遅延を取る為に多く作っておく # 送信信号 d = np.random.choice([0, 1], offset_n) x = m.modulate_qpsk(d) # 希望信号 d_s = np.random.choice([0, 1], offset_n) s = m.modulate_qpsk(d_s) # 送信側非線形 if self.tx_iqi == True: x_iq = m.iq_imbalance(x, self.gamma, self.phi) else: x_iq = x if self.pa == True: x_pa = m.sspa_rapp_ibo(x_iq, self.PA_IBO_dB, self.PA_rho) else: x_pa = x_iq # 通信路 # [[x[n], x[n-1]], x[x-1], x[n-1]]のように通信路の数に合わせる chanels_x_pa = np.array([ x_pa[i:i + self.h_si_len] for i in range(x_pa.size - self.h_si_len + 1) ]) chanels_y_si = self.h_si * chanels_x_pa y_si = np.sum(chanels_y_si, axis=1) # [[x[n], x[n-1]], x[x-1], x[n-1]]のように通信路の数に合わせる chanels_s = np.array( [s[i:i + self.h_s_len] for i in range(s.size - self.h_s_len + 1)]) chanels_s = self.h_s * chanels_s y_s = np.sum(chanels_s, axis=1) r = y_si + y_s + m.awgn(y_si.shape, self.sigma) self.a_sat = m.a_sat(r, LNA_IBO_dB)
def transceive_s(self): # 送信信号 self.d = np.random.choice([0, 1], (self.subcarrier * 2 * self.block, 1)) x_n = m.modulate_qpsk(self.d) x_p = x_n.reshape((self.subcarrier, self.block), order='F') x_idft = np.matmul(self.idft_mat, x_p) x_cp = ofdm.add_cp(x_idft, self.CP) x = x_cp self.x = x_cp.flatten(order='F') tx_x = x # 送信側非線形 if self.tx_iqi == True: tx_x = m.iq_imbalance(tx_x, self.gamma, self.phi) if self.pa == True: tx_x = m.sspa_rapp_ibo(tx_x, self.PA_IBO_dB, self.PA_rho, ofdm=True) x_rx = tx_x if self.h_si_len > 1: x_rx = np.zeros((self.h_si_len - 1 + tx_x.shape[0], tx_x.shape[1]), dtype=complex) x_rx[:(self.h_si_len - 1), 1:] = tx_x[-(self.h_si_len - 1):, :-1] x_rx[(self.h_si_len - 1):, :] = tx_x self.y = np.zeros( (self.subcarrier_CP * self.block, self.receive_antenna), dtype=complex) for receive_antenna_i in range(self.receive_antenna): h_si = self.h_si_list[receive_antenna_i] toeplitz_h_si = ofdm.toeplitz_channel(h_si.T, self.h_si_len, self.subcarrier, self.CP) r = np.matmul(toeplitz_h_si, x_rx) + m.awgn( (self.subcarrier + self.CP, self.block), self.sigma) # 受信側非線形 if self.lna == True: r = m.polynomial_amplifier(r, self.LNA_alpha_1, self.LNA_alpha_2) if self.rx_iqi == True: r = m.iq_imbalance(r, self.gamma, self.phi) y = r.flatten(order='F') self.y[:, receive_antenna_i] = y
def __init__(self, block: int, subcarrier: int, CP: int, sigma: float, gamma=0.0, phi=0.0, PA_IBO_dB=5, PA_rho=2, LNA_alpha_1=5, LNA_alpha_2=2, h_si_list=None, h_s_list=None, h_si_len=1, h_s_len=1, receive_antenna=1, tx_iqi=True, pa=True, lna=True, rx_iqi=True): self.block = block self.subcarrier = subcarrier self.CP = CP self.subcarrier_CP = subcarrier + CP # 必要な行列を生成する dft_mat = dft(subcarrier, scale="sqrtn") self.dft_mat = dft_mat self.idft_mat = dft_mat.conj().T self.cp_zero = np.hstack((np.zeros( (subcarrier, CP)), np.eye(subcarrier))) # ここまで # 送信信号 self.d = np.random.choice([0, 1], (subcarrier * 2 * block, 1)) x_n = m.modulate_qpsk(self.d) x_p = x_n.reshape((subcarrier, block), order='F') x_idft = np.matmul(self.idft_mat, x_p) x_cp = ofdm.add_cp(x_idft, CP) x = x_cp self.x = x_cp.flatten(order='F') tx_x = x # 送信側非線形 if tx_iqi == True: tx_x = m.iq_imbalance(tx_x, gamma, phi) if pa == True: tx_x = m.sspa_rapp_ibo(tx_x, PA_IBO_dB, PA_rho, ofdm=True) # 希望信号 self.d_s = np.random.choice([0, 1], (subcarrier * 2 * block, 1)) s_n = m.modulate_qpsk(self.d_s) # self.s = s_n # シリアルの状態を保持する s_p = s_n.reshape((subcarrier, block), order='F') s_idft = np.matmul(self.idft_mat, s_p) s_cp = ofdm.add_cp(s_idft, CP) self.tilde_s = s_cp x_rx = tx_x if h_si_len > 1: x_rx = np.zeros((h_si_len - 1 + tx_x.shape[0], tx_x.shape[1]), dtype=complex) x_rx[:(h_si_len - 1), 1:] = tx_x[-(h_si_len - 1):, :-1] x_rx[(h_si_len - 1):, :] = tx_x s_rx = s_cp if h_s_len > 1: s_rx = np.zeros((h_s_len - 1 + s_cp.shape[0], s_cp.shape[1]), dtype=complex) s_rx[:(h_s_len - 1), 1:] = s_cp[-(h_s_len - 1):, :-1] s_rx[(h_s_len - 1):, :] = s_cp self.y = np.zeros((self.subcarrier_CP * block, receive_antenna), dtype=complex) for receive_antenna_i in range(receive_antenna): h_si = h_si_list[receive_antenna_i] h_s = h_s_list[receive_antenna_i] toeplitz_h_si = ofdm.toeplitz_channel(h_si.T, h_si_len, subcarrier, CP) toeplitz_h_s = ofdm.toeplitz_channel(h_s.T, h_s_len, subcarrier, CP) r = np.matmul(toeplitz_h_si, x_rx) + np.matmul( toeplitz_h_s, s_rx) + m.awgn((subcarrier + CP, block), sigma) # 受信側非線形 if lna == True: r = m.polynomial_amplifier(r, LNA_alpha_1, LNA_alpha_2) if rx_iqi == True: r = m.iq_imbalance(r, gamma, phi) y = r.flatten(order='F') self.y[:, receive_antenna_i] = y
snr_max = 25 snr_dots = 6 snrs_db = np.linspace(snr_min, snr_max, snr_dots) sigmas = m.sigmas(snrs_db) # SNR(dB)を元に雑音電力を導出 error_array = np.zeros((len(snrs_db), ave)) for trials_index in tqdm(range(ave)): # h_s = m.channel(1, h_s_len) h_s = np.array([1 + 1j, 1 + 1j]).reshape((1, 2)) for sigma_index, sigma in enumerate(sigmas): noise_var = sigma**2 d_s = np.random.choice([0, 1], n) s = m.modulate_qpsk(d_s) H = toeplitz_chanel(h_s.T, h_s_len, L_w) chanels_s = np.array([ s[i:i + h_s_len] for i in range(s.size - h_s_len + 1) ]) # [[x[n], x[n-1]], x[x-1], x[n-1]]のように通信路の数に合わせる chanels_s = h_s * chanels_s y_s = np.sum(chanels_s, axis=1) r = y_s + m.awgn(y_s.shape, sigma) size = r.shape[0] r_vec = np.array([r[i:i + size - L_w] for i in range(L_w + 1)]) W = mmse(H, noise_var) z = np.matmul(W.conj().T, r_vec)
sigmas = m.sigmas(snrs_db) errors = np.zeros((params['SNR_NUM'], params['SNR_AVERAGE'])) q_errors = np.zeros((params['SNR_NUM'], params['SNR_AVERAGE'])) for trials_index in range(params['SNR_AVERAGE']): h_si = m.channel(1, params['chanel_len']) H = ofdm.toeplitz_channel(h_si.T, params['chanel_len'], params['subcarrier'], params['CP']) z_H = np.hstack((np.zeros((H.shape[0], params["subcarrier"] + params["CP"] - 3)), H)) Hc = ofdm.circulant_channel(h_si.T, params['chanel_len'], params['subcarrier']) D = F @ Hc @ FH D_1 = np.linalg.inv(D) for sigma_index, sigma in enumerate(sigmas): d = np.random.choice([0, 1], (params['subcarrier'] * 2 * params['block'], 1)) s_n = m.modulate_qpsk(d) s = s_n.reshape(params['subcarrier'], params['block']) x = np.matmul(FH, s) x_cp = ofdm.add_cp(x, params['CP']) x_receive = x_cp if params["chanel_len"] > 1: x_receive = np.zeros((params['chanel_len'] - 1 + x_cp.shape[0], x_cp.shape[1]), dtype=complex) x_receive[:(params["chanel_len"] - 1), 1:] = x_cp[-(params["chanel_len"] - 1):, :-1] x_receive[(params["chanel_len"] - 1):, :] = x_cp noise = m.awgn((params['subcarrier'] + params['CP'], params['block']), sigma) r = np.matmul(H, x_receive) + noise r_s = r.flatten()
def __init__(self, n, sigma, gamma=0.0, phi=0.0, PA_IBO_dB=5, PA_rho=2, LNA_IBO_dB=5, LNA_rho=2, h_si_list=None, h_s_list=None, h_si_len=1, h_s_len=1, receive_antenna=1, tx_iqi=True, pa=True, lna=True, rx_iqi=True): # 送信信号 self.d = np.random.choice([0, 1], n) self.x = m.modulate_qpsk(self.d) # 希望信号 self.d_s = np.random.choice([0, 1], n) self.s = m.modulate_qpsk(self.d_s) # 送信側非線形 if tx_iqi == True: self.x_iq = m.iq_imbalance(self.x, gamma, phi) else: self.x_iq = self.x if pa == True: self.x_pa = m.sspa_rapp_ibo(self.x_iq, PA_IBO_dB, PA_rho) else: self.x_pa = self.x_iq # 通信路 # 通信路がランダムの場合 if h_si_list is None: h_si_list = [m.channel(size=self.x_pa.size)] if h_s_list is None: h_s_list = [m.channel(size=self.s.size)] self.h_si_list = h_si_list self.h_s_list = h_s_list x_len = self.x_pa.size - h_si_len + 1 # 周波数選択性の場合,時間のずれを考慮すると長さがnではなくなる self.y = np.zeros((x_len, receive_antenna), dtype=complex) for i, (h_si, h_s) in enumerate(zip(h_si_list, h_s_list)): chanels_x_pa = np.array([ self.x_pa[i:i + h_si_len] for i in range(self.x_pa.size - h_si_len + 1) ]) # [[x[n], x[n-1]], x[x-1], x[n-1]]のように通信路の数に合わせる chanels_y_si = h_si * chanels_x_pa y_si = np.sum(chanels_y_si, axis=1) chanels_s = np.array([ self.s[i:i + h_s_len] for i in range(self.s.size - h_s_len + 1) ]) # [[x[n], x[n-1]], x[x-1], x[n-1]]のように通信路の数に合わせる chanels_s = h_s * chanels_s y_s = np.sum(chanels_s, axis=1) r = y_si + y_s + m.awgn(y_s.shape, sigma) # 受信側非線形 if lna == True: y_lna = m.sspa_rapp_ibo(r, LNA_IBO_dB, LNA_rho).squeeze() else: y_lna = r if rx_iqi == True: y_iq = m.iq_imbalance(y_lna, gamma, phi) else: y_iq = y_lna self.y[:, i] = y_iq