• danx
    了解作者
  • Python
    开发工具
  • 5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 5
    下载次数
  • 2020-02-28 11:23
    上传日期
使用python基于numpy编写函数和程序,完整实现了SC-FDE链路的仿真,包括调制、成型滤波、信道、同步、频偏补偿、均衡、解调。
SC-FDE.zip
  • communication_func.py
    14.3KB
  • SC-FDE.py
    7.2KB
内容介绍
import numpy as np import sequence_gen as sg import scipy.signal as sig def qam_sym(mod_type='QPSK'): # Description: generate random QAM modulated symbol(one) # Parameters: # mod_type : ['QPSK' '16QAM'] # returns: # y : QAM modulated symbol if mod_type == 'QPSK': QAM4_dic = np.array([-1+1j,-1-1j,+1+1j,+1-1j]) b=2 elif mod_type == '16QAM': QAM16_dic = np.array([-3+3j,-3+1j,-3-3j,-3-1j,-1+3j,-1+1j,-1-3j,-1-1j,3+3j,3+1j,3-3j,3-1j,1+3j,1+1j,1-3j,1-1j]) b=4 M = 2**b Es = 1 A = (3/2/(M-1)*Es)**0.5 y = np.zeros(shape=(1),dtype=complex) x = np.random.randint(0,M,size=(1),dtype=np.int32) if mod_type == 'QPSK': y = QAM4_dic[x] elif mod_type == '16QAM': y = QAM16_dic[x] y = y*A return y def qam_seq(sym_length,mod_type='QPSK'): # Description: generate random QAM modulated symbol(sequence) # Parameters: # sym_length : the QAM symbol sequence length # mod_type : ['QPSK' '16QAM'] # returns: # y : QAM modulated symbol sequence y = np.zeros(shape=(sym_length),dtype=complex) for i in range(0,sym_length): y[i] = qam_sym(mod_type) return y def qam_map(x,mod_type='QPSK'): # Description: group input [1 0] sequence and map into [0 M-1] # sequence according to mod_type in natural order # Parameters: # x : input [1 0] sequence # mod_type : ['QPSK' '16QAM'] # returns: # sym : mapped [0 M-1] sequence x[np.where(x!=0)] = 1 bit_len = len(x) if(mod_type=='QPSK'): if bit_len%2 != 0: print('Error: not exact division') return else: sym_len = np.int32(bit_len/2) tmp = np.reshape(x,[2,sym_len],order='F') sym = 2*tmp[0,:]+tmp[1,:] elif(mod_type=='16QAM'): if bit_len%4 != 0: print('Error: not exact division') return else: sym_len = np.int32(bit_len/4) tmp = np.reshape(x,[4,sym_len],order='F') sym = 8*tmp[0,:]+4*tmp[1,:]+2*tmp[2,:]+tmp[3,:] return sym def qam_demap(x,mod_type='QPSK'): # Description: demap input [0 M-1] sequence into [1 0] sequence # according to mod_type in natural order # Parameters: # x : input [0 M-1] sequence # mod_type : ['QPSK' '16QAM'] # returns: # sym : demapped [1 0] sequence x_len = len(x) tmp_x = np.int32(np.copy(x)) if(mod_type=='QPSK'): tmp = np.zeros(shape=(x_len,2),dtype=np.int32) for i in range(0,x_len): tmp[i,1] = tmp_x[i]&1 tmp[i,0] = (tmp_x[i]&2)/2 bit = np.reshape(tmp,[x_len*2]) elif(mod_type=='16QAM'): tmp = np.zeros(shape=(x_len,4),dtype=np.int32) for i in range(0,x_len): tmp[i,3] = tmp_x[i]&1 tmp[i,2] = (tmp_x[i]&2)/2 tmp[i,1] = (tmp_x[i]&4)/4 tmp[i,0] = (tmp_x[i]&8)/8 bit = np.reshape(tmp,[x_len*4]) return bit def qam_mod(sym,mod_type='QPSK'): # Description: modulate input [0 M-1] sequence into symbol sequence # according to mod_type in gray order # Parameters: # sym : input [0 M-1] sequence # mod_type : ['QPSK' '16QAM'] # returns: # y : modulated symbol sequence sym_len = len(sym) y = np.zeros(shape=(sym_len),dtype=complex) if(mod_type=='QPSK'): QAM4_dic = np.array([-1+1j,-1-1j,+1+1j,+1-1j]) b=2 for i in range(0,sym_len): y[i] = QAM4_dic[sym[i]] elif(mod_type=='16QAM'): QAM16_dic = np.array([-3+3j,-3+1j,-3-3j,-3-1j,-1+3j,-1+1j,-1-3j,-1-1j,3+3j,3+1j,3-3j,3-1j,1+3j,1+1j,1-3j,1-1j]) b=4 for i in range(0,sym_len): y[i] = QAM16_dic[sym[i]] M = 2**b Es = 1 A = (3/2/(M-1)*Es)**0.5 y = y*A return y def qam_hardDemod(x,mod_type='QPSK'): # Description: hard demodulate input symbol sequence into [0 M-1] # sequence according to mod_type in gray order # Parameters: # x : input symbol sequence # mod_type : ['QPSK' '16QAM'] # returns: # y : demodulated [0 M-1] sequence Es = 1 y = np.zeros(shape=(len(x)),dtype=np.int32) if mod_type=='QPSK': QAM4_dic = np.array([-1+1j,-1-1j,+1+1j,+1-1j]) b = 2 M = 2**b A = (3/2/(M-1)*Es)**0.5 x_tmp = np.copy(x)/A for i in range(0,len(x)): y[i] = np.argmin(np.abs(QAM4_dic-x_tmp[i])) elif mod_type=='16QAM': QAM16_dic = np.array([-3+3j,-3+1j,-3-3j,-3-1j,-1+3j,-1+1j,-1-3j,-1-1j,3+3j,3+1j,3-3j,3-1j,1+3j,1+1j,1-3j,1-1j]) b = 4 M = 2**b A = (3/2/(M-1)*Es)**0.5 x_tmp = np.copy(x)/A for i in range(0,len(x)): y[i] = np.argmin(np.abs(QAM16_dic-x_tmp[i])) return y def errorRatio_calc(x,y): # Description: calculate the ratio where x and y are different # Parameters: # x : input sequence 1 # y : input sequence 2 # returns: # ratio : the calculated ratio if len(x)!=len(y): print('Error: length not equal') return cnt = len(np.argwhere(x!=y)) ratio = cnt/len(x) return ratio def ofdm_sym(subca_num,mod_type='QPSK'): # Description: generate random OFDM symbol(one) # (subcarrier 0 not used) with specified modulation # type and subcarrier number(subcarrier automatically # zero-padded for fft) # Parameters: # subca_num : subcarrier number used # mod_type : ['QPSK' '16QAM'] # returns: # y : QAM/OFDM modulated symbol i = 1 while(2**i<subca_num): i = i + 1 true_sub_num = 2**i y = np.zeros(shape=(true_sub_num),dtype=complex) x = qam_seq(subca_num,mod_type) x[0] = 0 if (subca_num&1) == 0: y_lower = np.int32(np.linspace(0,subca_num/2-1,subca_num/2,endpoint=True)) y_upper = np.int32(np.linspace(true_sub_num-subca_num/2,true_sub_num-1,subca_num/2,endpoint=True)) x_upper = np.int32(y_lower+subca_num/2) else: y_lower = np.int32(np.linspace(0,(subca_num+1)/2-1,(subca_num+1)/2,endpoint=True)) y_upper = np.int32(np.linspace(true_sub_num-(subca_num+1)/2+1,true_sub_num-1,(subca_num-1)/2,endpoint=True)) x_upper = np.int32(np.delete(y_lower,0)+(subca_num-1)/2) y[y_lower] = x[y_lower] y[y_upper] = x[x_upper] y = np.fft.ifft(y) return y,true_sub_num def ofdm_seq(sym_length,subca_num,mod_type='QPSK'): # Description: generate random OFDM symbol(sequence) # (subcarrier 0 not used) with specified modulation # type and subcarrier number(subcarrier automatically # zero-padded for fft) # Parameters: # sym_length : the OFDM symbol sequence length # subca_num : subcarrier number used # mod_type : ['QPSK' '16QAM'] # returns: # y : QAM/OFDM modulated symbol sequence i = 1 while(2**i<subca_num): i = i + 1 true_sub_num = 2**i y = np.zeros(shape=(sym_length*true_sub_num),dtype=complex) if (subca_num&1) == 0: y_lower = np.int32(np.linspace(0,subca_num/2-1,subca_num/2,endpoint=True)) y_upper = np.int32(np.linspace(true_sub_num-subca_num/2,true_sub_num-1,subca_num/2,endpoint=True)) x_upper = np.int32(y_lower+subca_num/2) else: y_lower = np.int32(np.linspace(0,(subca_num+1)/2-1,(subca_num+1)/2,endpoint=True)) y_upper = np.int32(np.linspace(true_sub_num-(subca_num+1)/2+1,true_sub_num-1,(subca_num-1)/2,endpoint=True)) x_upper = np.int32(np.delete(y_lower,0)+(subca_num-1)/2) id_sym = np.int32(np.linspace(0,true_sub_num-1,true_sub_num,endpoint=True)) for i in range(0,sym_length): x = qam_seq(subca_num,mod_type) x[0] = 0 d = np.zeros(shape=(true_sub_num),dtype=complex) d[y_lower] = x[y_lower]
评论
    相关推荐
    • ICI_OFDM.rar
      This project investigates three methods for combating the effects of ICI: ICI self-cancellation (SC), maximum likelihood (ML) estimation, and extended Kalman filter (EKF) method. These three methods ...
    • Circularorthogonalsequencesbasedchannelestimation
      Circular orthogonal sequences based channel estimation for MIMO SC-FDE systems
    • sc_fed.zip
      SCFDE的仿真,使用qpsk,还有相关文档
    • 5.rar
      A Time-Division Multiple-Access SC-FDE System With IBI Suppression for UWB Communications
    • MIMO.rar
      Low complexity maximum likelihood MIMO signal detection algorithm
    • Single Carrier FDMA -- A NEW AIR INTERFACE FOR LONG TERM EVOLUTI
      MATLABR Simulation Codes for SC/FDE 151 MATLABR Simulation Codes for SC-FDMA (Link Level) 155 MATLABR Simulation Codes for SC-FDMA and OFDMA (PAPR) 159 Appendix A: Derivation of Time Domain Symbols...
    • gr-gfdm:GNU无线电中的广义频分复用
      GNU Radio GFDM调制器/解调器 gr-gfdm项目是一个免费软件包,旨在在GNU Radio框架中提供广义... GFDM可以通过并行化子载波上的几个SC-FDE流来描述。 发射符号被定位在时间/频率网格中,并在子载波方向上施加脉冲。 在脉
    • ofdmdemo.rar
      课件。适合于初学者。基本的东西,ofdm的。
    • USB-COM(HL340).rar
      usb转串口,找了很久才找到,现在别的地方很难下到,要不用不了,我这个可以用 HL340D 的
    • NAND FLASH的读写程序.rar
      Nand flash 读写程序 C语言代码,可以给U盘开发者参考 可以读写三星各种型号的Nand flash芯片