%% bit
clear all;
clc;
%SymbolMapping_ = 'Binary';
SymbolMapping_ = 'Gray';
qpsk_mo = comm.QPSKModulator('SymbolMapping',SymbolMapping_,...
'BitInput',true ); %Binary | Gray
qpsk_demo = comm.QPSKDemodulator('SymbolMapping',SymbolMapping_,...
'BitOutput',true);
snr = 0:9;
bit_number = 4*10^5;
for i = 1:length(snr)
if( i == 1)
tic;
end
bit_in = randi([0 1],1,bit_number).'; %Gray 码 0: 00 , 1:01 , 2:11 ,3:10
bit_channel = qpsk_mo(bit_in);%归一化输出
bit_channel_awgn = awgn(bit_channel,snr(i));
%scatterplot(bit_channel_awgn);
bit_out = qpsk_demo(bit_channel_awgn);
Totalerror_bit = length(find(bit_in ~= bit_out));
if i==1
p_bit = zeros(1,length(snr));
end
p_bit(i) = Totalerror_bit/length(bit_in);
clear bit_in bit_out bit_channel_awgn;
fprintf('%d\n',i);
toc;
end
semilogy(snr,p_bit,'ks-');
title(['AWGN QPSK 硬判决' ' ' SymbolMapping_ ' ' num2str(bit_number/10^6) 'Mbit']);
grid on;hold on;
xlabel('SNR');ylabel('BER');
%% MIMO QPSK
% clc;
% clear all;
%SymbolMapping_ = 'Binary';
SymbolMapping_ = 'Gray';
qpsk_mo = comm.QPSKModulator('SymbolMapping',SymbolMapping_,...
'BitInput',true );
qpsk_demo = comm.QPSKDemodulator('SymbolMapping',SymbolMapping_,...
'BitOutput',true);
SNR_dB=0:9;
Frame=10^7/4;
tic;
for i=1:length(SNR_dB)
ErrorNum=0;
for j =1:1:Frame
bit_in = randi([0 1],1,4).';
bit_channel = qpsk_mo(bit_in);%归一化输出
x1 = bit_channel(1);
x2 = bit_channel(2);
%---------------------------进行空时编码---------------------------------
X_1 = [x1 -conj(x2)];
X_2 = [x2 conj(x1)];
X_1_channel = awgn(X_1,SNR_dB(i));
X_2_channel = awgn(X_2,SNR_dB(i));
X1_1_channel = awgn(X_1,SNR_dB(i));
X1_2_channel = awgn(X_2,SNR_dB(i));
R1 = X_1_channel + X_2_channel; % R(1)=x1+x2 R(2)=(-conj(x2))+conj(x1)
R2 = X1_1_channel + X1_2_channel;
%---------------------------进行空时解码--------------------------------
% A=h1*conj(h1)+h2*conj(h2);
% X1=(conj(h1)*R(1)+h2*conj(R(2)))/A;
% X2=(conj(h2)*R(1)-h1*conj(R(2)))/A;
X11=(R1(1)+conj(R1(2)))/2;
X21=(R1(1)-conj(R1(2)))/2;
bit_channel_awgn1 = [X11 X21].';
X12=(R2(1)+conj(R2(2)))/2;
X22=(R2(1)-conj(R2(2)))/2;
bit_channel_awgn2 = [X12 X22].';
bit_channel_awgn = (bit_channel_awgn1 + bit_channel_awgn2)/2;
bit_out = qpsk_demo(bit_channel_awgn);
ErrorNum=ErrorNum+length(find(bit_in ~= bit_out));
end
fprintf('%d\n',i);
toc;
P(i)=ErrorNum/(Frame*4);
end
semilogy(SNR_dB,P,'k+-');
title(['AWGN 2*1-MISO-QPSK 硬判决' ' ' 'Gray' ' ' num2str(4*Frame/10^6) 'Mbit']);
grid on;
xlabel('SNR');ylabel('BER');