您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > MIMO-OFDM-源程序
%STBC_MIMO_OFDM.m%这是一个基于空时分组编码的MIMO_OFDM通信系统的仿真设计。%此系统包括QPSK调制解调,IFFT调制,空时编解码,基于训%练符号的信道估计等通信模块。clearallcloseallclc%+++++++++++++++++++++++++++变量++++++++++++++++++++++++++++++i=sqrt(-1);IFFT_bin_length=512;%傅立叶变换抽样点数目carrier_count=100;%子载波数目symbols_per_carrier=66;%符号数/载波cp_length=10;%循环前缀长度addprefix_length=IFFT_bin_length+cp_length;M_psk=4;bits_per_symbol=log2(M_psk);%位数/符号%[x1x2;-x2*x1*]二天线发送矩阵%O=[12;-2+j1+j];%[x1-x2-x3;x2*x1*0;x3*0x1*;0-x3*x2*]三天线发送矩阵O=[1-2-3;2+j1+j0;3+j01+j;0-3+j2+j];co_time=size(O,1);Nt=size(O,2);%发射天线数目Nr=2;%接收天线数目%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%+++++++++++++++++++++++++++发射机++++++++++++++++++++++++++++++disp('--------------start-------------------');num_X=1;forcc_ro=1:co_timeforcc_co=1:Ntnum_X=max(num_X,abs(real(O(cc_ro,cc_co))));endendco_x=zeros(num_X,1);forcon_ro=1:co_timeforcon_co=1:Nt%用于确定矩阵“O”中元素的位置,符号以及共轭情况ifabs(real(O(con_ro,con_co)))~=0delta(con_ro,abs(real(O(con_ro,con_co))))=sign(real(O(con_ro,con_co)));epsilon(con_ro,abs(real(O(con_ro,con_co))))=con_co;co_x(abs(real(O(con_ro,con_co))),1)=co_x(abs(real(O(con_ro,con_co))),1)+1;eta(abs(real(O(con_ro,con_co))),co_x(abs(real(O(con_ro,con_co))),1))=con_ro;coj_mt(con_ro,abs(real(O(con_ro,con_co))))=imag(O(con_ro,con_co));endendendeta=eta.';eta=sort(eta);eta=eta.';%坐标:(1to100)+14=(15:114)carriers=(1:carrier_count)+(floor(IFFT_bin_length/4)-floor(carrier_count/2));%坐标:256-(15:114)+1=257-(15:114)=(242:143)conjugate_carriers=IFFT_bin_length-carriers+2;tx_training_symbols=training_symbol(Nt,carrier_count);baseband_out_length=carrier_count*symbols_per_carrier;snr_min=3;%最小信噪比snr_max=15;%最大信噪比graph_inf_bit=zeros(snr_max-snr_min+1,2,Nr);%绘图信息存储矩阵graph_inf_sym=zeros(snr_max-snr_min+1,2,Nr);forSNR=snr_min:snr_maxclcdisp('WaituntilSNR=');disp(snr_max);SNRn_err_sym=zeros(1,Nr);n_err_bit=zeros(1,Nr);Perr_sym=zeros(1,Nr);Perr_bit=zeros(1,Nr);re_met_sym_buf=zeros(carrier_count,symbols_per_carrier,Nr);re_met_bit=zeros(baseband_out_length,bits_per_symbol,Nr);%生成随机数用于仿真baseband_out=round(rand(baseband_out_length,bits_per_symbol));%二进制向十进制转换de_data=bi2de(baseband_out);%PSK调制data_buf=pskmod(de_data,M_psk,0);carrier_matrix=reshape(data_buf,carrier_count,symbols_per_carrier);%取数为空时编码做准备,此处每次取每个子载波上连续的两个数fortt=1:Nt:symbols_per_carrierdata=[];forii=1:Nttx_buf_buf=carrier_matrix(:,tt+ii-1);data=[data;tx_buf_buf];endXX=zeros(co_time*carrier_count,Nt);forcon_r=1:co_time%进行空时编码forcon_c=1:Ntifabs(real(O(con_r,con_c)))~=0ifimag(O(con_r,con_c))==0XX((con_r-1)*carrier_count+1:con_r*carrier_count,con_c)=data((abs(real(O(con_r,con_c)))-1)*carrier_count+1:abs(real(O(con_r,con_c)))...*carrier_count,1)*sign(real(O(con_r,con_c)));elseXX((con_r-1)*carrier_count+1:con_r*carrier_count,con_c)=conj(data((abs(real(O(con_r,con_c)))-1)*carrier_count+1:abs(real(O(con_r,con_c)))...*carrier_count,1))*sign(real(O(con_r,con_c)));endendendend%空时编码结束XX=[tx_training_symbols;XX];%添加训练序列rx_buf=zeros(1,addprefix_length*(co_time+1),Nr);forrev=1:Nrforii=1:Nttx_buf=reshape(XX(:,ii),carrier_count,co_time+1);IFFT_tx_buf=zeros(IFFT_bin_length,co_time+1);IFFT_tx_buf(carriers,:)=tx_buf(1:carrier_count,:);IFFT_tx_buf(conjugate_carriers,:)=conj(tx_buf(1:carrier_count,:));time_matrix=ifft(IFFT_tx_buf);time_matrix=[time_matrix((IFFT_bin_length-cp_length+1):IFFT_bin_length,:);time_matrix];tx=time_matrix(:)';%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%+++++++++++++++++++++++++++信道++++++++++++++++++++++++++++++%d=randint(1,4,[1,7]);%4多经信道模拟%a=randint(1,4,[2,7])/10;tx_tmp=tx;d=[4,5,6,2;4,5,6,2;4,5,6,2;4,5,6,2];a=[0.2,0.3,0.4,0.5;0.2,0.3,0.4,0.5;0.2,0.3,0.4,0.5;0.2,0.3,0.4,0.5];forjj=1:size(d,2)copy=zeros(size(tx));forkk=1+d(ii,jj):length(tx)copy(kk)=a(ii,jj)*tx(kk-d(ii,jj));endtx_tmp=tx_tmp+copy;endtxch=awgn(tx_tmp,SNR,'measured');%添加高斯白噪声rx_buf(1,:,rev)=rx_buf(1,:,rev)+txch;end%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%+++++++++++++++++++++++++++接收机++++++++++++++++++++++++++++++rx_spectrum=reshape(rx_buf(1,:,rev),addprefix_length,co_time+1);rx_spectrum=rx_spectrum(cp_length+1:addprefix_length,:);FFT_tx_buf=zeros(IFFT_bin_length,co_time+1);FFT_tx_buf=fft(rx_spectrum);spectrum_matrix=FFT_tx_buf(carriers,:);Y_buf=(spectrum_matrix(:,2:co_time+1));Y_buf=conj(Y_buf');spectrum_matrix1=spectrum_matrix(:,1);Wk=exp((-2*pi/carrier_count)*i);L=10;p=zeros(L*Nt,1);forjj=1:Ntforl=0:L-1forkk=0:carrier_count-1p(l+(jj-1)*L+1,1)=p(l+(jj-1)*L+1,1)+spectrum_matrix1(kk+1,1)*conj(tx_training_symbols(kk+1,jj))*Wk^(-(kk*l));endendend%q=zeros(L*Nt,L*Nt);%forii=1:Nt%forjj=1:Nt%forl1=0:L-1%forl2=0:L-1%forkk=0:carrier_count-1%q(l2+(ii-1)*L+1,l1+(jj-1)*L+1)=q(l2+(ii-1)*L+1,l1+(jj-1)*L+1)+tx_training_symbols(kk+1,ii)*conj(tx_training_symbols(kk+1,jj))*Wk^(-(kk*(-l1+l2)));%end%end%end%end%end%h=inv(q)*p;h=p/carrier_count;H_buf=zeros(carrier_count,Nt);forii=1:Ntforkk=0:carrier_count-1forl=0:L-1H_buf(kk+1,ii)=H_buf(kk+1,ii)+h(l+(ii-1)*L+1,1)*Wk^(kk*l);endendendH_buf=conj(H_buf');RRR=[];forkk=1:carrier_countY=Y_buf(:,kk);H=H_buf(:,kk);forco_ii=1:num_Xforco_tt=1
本文标题:MIMO-OFDM-源程序
链接地址:https://www.777doc.com/doc-6711263 .html