【MIMO通訊】基於matlab空時分組編碼MIMO_OFDM通訊系統模擬【含Matlab原始碼 663期】
阿新 • • 發佈:2021-06-24
一、簡介
基於空時分組編碼MIMO_OFDM通訊模擬
二、原始碼
%main_STBC_MIMO_OFDM.m %這是一個基於空時分組編碼的MIMO_OFDM通訊系統的模擬設計。 %此係統包括QPSK調製解調,IFFT調製,空時編解碼,基於訓 %練符號的通道估計等通訊模組。 clear all close all clc %+++++++++++++++++++++++++++變數++++++++++++++++++++++++++++++ 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); %位數/符號 %[x1 x2;-x2* x1*] 二天線傳送矩陣 % O=[1 2;-2+j 1+j]; %[x1 -x2 -x3;x2* x1* 0;x3* 0 x1*;0 -x3* x2*] 三天線傳送矩陣 O=[1 -2 -3;2+j 1+j 0;3+j 0 1+j;0 -3+j 2+j]; co_time=size(O,1); Nt=size(O,2); %發射天線數目 Nr=2; %接收天線數目 %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %+++++++++++++++++++++++++++發射機++++++++++++++++++++++++++++++ disp('--------------start-------------------'); num_X=1; for cc_ro=1:co_time for cc_co=1:Nt num_X=max(num_X,abs(real(O(cc_ro,cc_co)))); end end co_x=zeros(num_X,1); for con_ro=1:co_time for con_co=1:Nt %用於確定矩陣“O”中元素的位置,符號以及共軛情況 if abs(real(O(con_ro,con_co)))~=0 delta(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)); end end end eta=eta.'; eta=sort(eta); eta=eta.'; % 座標: (1 to 100) + 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); for SNR=snr_min:snr_max clc disp('Wait until SNR=');disp(snr_max); SNR n_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); %取數為空時編碼做準備,此處每次取每個子載波上連續的兩個數 for tt=1:Nt:symbols_per_carrier data=[]; for ii=1:Nt tx_buf_buf=carrier_matrix(:,tt+ii-1); data=[data;tx_buf_buf]; end XX=zeros(co_time*carrier_count,Nt); for con_r=1:co_time %進行空時編碼 for con_c=1:Nt if abs(real(O(con_r,con_c)))~=0 if imag(O(con_r,con_c))==0 XX((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))); else XX((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))); end end end end %空時編碼結束 XX=[tx_training_symbols;XX]; %新增訓練序列 rx_buf=zeros(1,addprefix_length*(co_time+1),Nr); for rev=1:Nr for ii=1:Nt tx_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]; for jj=1:size(d,2) copy=zeros(size(tx)) ; for kk = 1 + d(ii,jj): length(tx) copy(kk) = a(ii,jj)*tx(kk - d(ii,jj)) ; end tx_tmp=tx_tmp+copy; end txch=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); for jj=1:Nt for l=0:L-1 for kk=0:carrier_count-1 p(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)); end end end %q=zeros(L*Nt,L*Nt); %for ii=1:Nt % for jj=1:Nt % for l1=0:L-1 % for l2=0:L-1 % for kk=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); for ii=1:Nt for kk=0:carrier_count-1 for l=0:L-1 H_buf(kk+1,ii)=H_buf(kk+1,ii)+h(l+(ii-1)*L+1,1)*Wk^(kk*l); end end end
三、執行結果
四、備註
版本:2014a
完整程式碼或代寫加1564658423