经验 24 分贝 0 家园分 67 在线时间: 8 小时 最后登录: 2015-7-27 帖子: 20 精华: 0 注册时间: 2014-10-19 UID: 1061105
注册:2014-10-19
发表于 2015-7-25 20:16:47
| 显示全部楼层
本书在第352页的预编码设计仿真中,H_used如果不是方阵怎么办啊?
clear all;
clc;
warning('off','comm bsolete:randint');
mode=1;
N_frame=10;
N_packet=1000;
b=2;
M=2^b;
mod_obj=modem.qammod('M',M,'SymbolOrder','Gray','InputType','bit');%调制器
demod_obj=modem.qamdemod(mod_obj);%解调器
NT=4;%基站天线数
N_user=20;
N_act_user=4;
sq2=sqrt(2);
I=eye(N_act_user,NT);
N_pbits=N_frame*NT*b;%每组的bit数
N_tbits=N_pbits*N_packet;%总共的bit数
% fprintf('=========================================================\n');
% fprintf('Pre-MMSE transmission');
% fprintf('\n %d x %d MIMO\n %d QAM',NT,NR,M);
% fprintf('\n SImulation bits:%d',N_tbits);
% fprintf('=========================================================\n');
SNRdBs=[0:2:20];%信噪比,在每一种信噪比下,即每个环境下,通过调制,解调,计算误码率
for i_SNR=1:length(SNRdBs)
SNRdB=SNRdBs(i_SNR);
noise_var=NT*0.5*10^(-SNRdB/10);
sigma=sqrt(noise_var);
rand('seed',1);
rand('seed',1);
N_ebits=0;
%%%%%%%%%%%%%%%%%%%%%%%%%发射机%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i_packet=1:N_packet;
msg_bit=randint(N_pbits,1);
symbol=modulate(mod_obj,msg_bit);
Scale=modnorm(symbol,'avpow',1);
Symbol_nomalized=reshape(Scale*symbol,NT,N_frame);
for i_user=1:N_user
H(i_user,:)=(randn(1,NT)+j*randn(1,NT))/sq2;
Channel_norm(i_user)=norm(H(i_user,:));
end
[CH_norm,Index]=sort(Channel_norm,'descend');
H_used =H(Index(1:N_act_user),:);
temp_W=H_used'*inv(H_used*H_used'+(mode==1)*noise_var*I);
beta=sqrt(NT/trace(temp_W*temp_W'));
W=beta*temp_W;
Tx_signal=W*Symbol_nomalized;
%%%%%%%%%%%%%%%%%%%%%%%%信道和噪声%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rx_signal=H_used*Tx_signal+sigma*(randn(N_act_user,N_frame)+j*randn(N_act_user,N_frame));
%%%%%%%%%%%%%%%%%%%%%%%接收机%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y=Rx_signal/beta;
Symbol_hat=reshape(y/Scale,NT*N_frame,1);
msg_hat=demodulate(demod_obj,Symbol_hat);
N_ebits=N_ebits+sum(msg_hat~=msg_bit);
end
BER(i_SNR)=N_ebits/N_tbits;
end
semilogy(SNRdBs,BER,'-r^','LineWidth',1)
hold on
grid on
xlabel('SNR[dB]');
ylabel('BER');
legend('pre_MMSE','pre_ZF');