非理想信道状态下的线性预编码matlab仿真,case1用迫零,case2用MMSE,求两段代码
%this file contains several precoding schemes for imperfect CSI
clear;
clc;
randn('state',0);
rand('state',0);
j=sqrt(-1);
% parameter setting for MIMO system
Nt=4; % transmit antenna
Nr=4; % receive antenna; Nr>=Nt
% modulation mode
modu_order=2; % [2 4 6] for [4QAM 16QAM 64QAM];
M=2^modu_order;
toll=sqrt(M);
qam_power=(M-1)/6; % average tranmit power for M-QAM
Es=Nt*qam_power;
% information parameter
block_number=100; % one realization of channel for one block
block_length=10;
% other initial parameters
case_set=[1]; % standing for different precoding schemes
s_shift=0.5; % constellation shift to get integer values
err_methods=[];
err_blocks=[];
err_method_snr=[];
err_snr=[];
const=1/2;
% SNR setting
EbN0dB=25;%[0:2.5:25];
%----------------begin of SNR iteration ----------------------------------
for snr_index=1:length(EbN0dB)
snr = 10.^(EbN0dB(snr_index)/10);
sigma2=Nr*(qam_power)/(modu_order*snr); % the variance(power) of the complex noise, equation (3.14) in P.H.D paper
sigma=sqrt(sigma2); % the standard variance of the equivalent real noise
block_number
%-----------------begin of block iteration -----------------------------
for block_number_index = 1:block_number
% generating channel: zero-mean and unit-variance
% block-satic flat rayleigh fading channel;
% The channel is static in every frame and i.i.d from block to block
Hc = (randn(Nr,Nt)+j*randn(Nr,Nt))/sqrt(2);
% translate complex channel into real model
Hr = real(Hc);
Hi = imag(Hc);
H = [Hr,-Hi;Hi,Hr];
pinv_H=inv(H);
% generating noise
Nc=(sigma)*(randn(Nr,block_length)+j*randn(Nr,block_length))/sqrt(2);
N=[real(Nc);imag(Nc)];
% generating information source
info_bit=round(rand(block_length*Nr,1)*(M-1));
info_sym=qammod(info_bit,M)*const; % modulation, M-QAM constellation,not gray code
info_sym=reshape(info_sym,Nr,block_length);
info_sym_real=[real(info_sym);imag(info_sym)]; % translate into real model
info_sym_real_shift=info_sym_real-s_shift; % shift constellation into integer position
info_power=trace(info_sym_real_shift*info_sym_real_shift'); % transmit symbol power for one realization
ite=(trace(N*N')/info_power); % % for MMSE case
%--------------------begin of different precoding schmems for comparsion-----------------------
for case_index = 1:length(case_set)
testcase = case_set(case_index);
switch testcase
case 1 %ZF-THP
x=info_sym_real_shift;
FF=pinv_H;
Y=H*FF*x+N;
r=Y;
case 2 case 3
end
rece = mod_toll(r+s_shift,toll); % modulo operation
rece_complex =rece(1:(end/2),:)+j*rece((end/2)+1:end,:); % translate into complex model
rece_sym=qamdemod(rece_complex/const,M); % demodulation, M-QAM
rece_sym=reshape(rece_sym,size(rece_sym,1)*size(rece_sym,2),1); % reshape into column vector
err_per_method=biterr(rece_sym,info_bit); % bit error caculation for one scheme
err_methods=[err_methods;err_per_method];
err_per_method=[];
end
%-------------------end of different precoding schmems for comparsion----------------------
err_blocks=[err_blocks err_methods]; % error number for block number iteration ( ie. all blocks)
err_methods=[];
end
%-----------------end of block iteration -----------------------------
err_blocks=sum(err_blocks,2);
err_blocks_ratio=err_blocks/(block_length*Nr*log2(M)* block_number); % caculate all error ratio for one SNR realization
err_snr=[err_snr err_blocks_ratio];
err_blocks=[];
err_blocks_ratio=[];
%-------------- change block_number for high SNRs --------------------
if(block_number~=20000)
if (snr_index>1)&&(snr_index<length(EbN0dB))
snr_intval=[EbN0dB(snr_index)-EbN0dB(snr_index-1)];
slope=max(abs((err_snr(:,snr_index-1))-(err_snr(:,snr_index))));
err_snr_min=min(err_snr(:,snr_index));
predict_err=err_snr_min-slope;
if (predict_err)<10e-4
predict_err=10e-4;
end
if err_snr_min==0
err_snr_min=10e-6;
end
block_number=block_number*err_snr_min/predict_err;
block_number=abs(block_number);
if (block_number)>20000 || (block_number)<10
block_number=20000;
end
end
end
end
%----------------end of SNR iteration ----------------------------------
semilogy(EbN0dB,err_snr(1,:),'r-s',EbN0dB,err_snr(2,:),'r-d',EbN0dB,err_snr(3,:),'k-s',EbN0dB,err_snr(4,:),'k-d',EbN0dB,err_snr(5,:),'b-s',EbN0dB,err_snr(6,:),'b-d',EbN0dB,err_snr(7,:),'g-s',EbN0dB,err_snr(8,:),'g-d');
grid on;