等增益合并
clear;
N=10^6;
data=randi([0,1],1,N);
x=2*data-1;
s=zeros(1,N);
ber_EGC=zeros(1,N);
for snr_dB=1:1:20
error=0;
h1=((randn(1,N)+(randn(1,N)*1i)))/sqrt(2);
h2=((randn(1,N)+(randn(1,N)*1i)))/sqrt(2);
c1=h1.*x;
c2=h2.*x;
y1=awgn(c1,snr_dB,'measured');
y2=awgn(c2,snr_dB,'measured');
y_rec = y1.*exp(-1i*angle(h1)) + y2 .*exp(-1i*angle(h2));
H=abs(h1)+abs(h2);
yHat = y_rec./H;
ipHat = real(yHat)>0;
ber_EGC(snr_dB) = size(find([data- ipHat]),2);
ber_EGC(snr_dB)=ber_EGC(snr_dB)/N;
end
figure;
semilogy(ber_EGC,'go-');
legend('EGC');
xlabel('SNR');
ylabel('BER');
title('BER for 1tx vs 2rx');
最大比合并
N=10^6;
data=randi([0,1],1,N);
x=2*data-1;
s=zeros(1,N);
ber_MRC=zeros(1,N);
for snr_dB=1:1:20
error=0;
h1=(randn(1,N)+(randn(1,N)*1i))/sqrt(2);
h2=(randn(1,N)+(randn(1,N)*1i))/sqrt(2);
c1=h1.*x;
c2=h2.*x;
y1=awgn(c1,snr_dB,'measured');
y2=awgn(c2,snr_dB,'measured');
y_rec =conj(h1).*y1+conj(h2).*y2;
H=(abs(h1)).^2+(abs(h2)).^2;
yHat = y_rec./H;
ipHat = real(yHat)>0;
ber_MRC(snr_dB) = size(find([data- ipHat]),2);
ber_MRC(snr_dB)=ber_MRC(snr_dB)/N;
end
figure;
semilogy(ber_MRC,'k*-');
legend('MRC');
xlabel('SNR');
ylabel('BER');
title('BER for 1tx vs 2rx');
选择合并
N=10^6;
data=randi([0,1],1,N);
x=2*data-1;
s=zeros(1,N);
ber_SC=zeros(1,N);
for snr_dB=1:20
h1=(randn(1,N)+(randn(1,N)*1i))/sqrt(2);
h2=(randn(1,N)+(randn(1,N)*1i))/sqrt(2);
c1=h1.*x;
c2=h2.*x;
y1=awgn(c1,snr_dB,'measured');
y2=awgn(c2,snr_dB,'measured');
hPower1 = sum(h1.*conj(h1));
hPower2 = sum(h2.*conj(h2));
if(hPower1>hPower2)
y_rec=y1;
H=h1;
else
y_rec=y2;
H=h2;
end
error=0;
yHat = y_rec./H;
ipHat = real(yHat)>0;
ber_SC(snr_dB) = size(find([data- ipHat]),2);
ber_SC(snr_dB)=ber_SC(snr_dB)/N;
end
figure;
semilogy(ber_SC,'m*-');hold on;
legend('SC');
xlabel('SNR');
ylabel('BER');
title('BER for 1tx vs 2rx');