Amplify-And-Forward (AF) Relaying of Cooperative Diversity

MATLAB PROGRAM

N=10^6;%Number of bits

b=rand(1,N)>0.5;%Generate 0s and 1s

Tx=2.*b-1;%NRZ

SNRdB=0:2:30;%SNR in dB

snr = 10.^(0.1 .* SNRdB); 

nErr = zeros(1,length(SNRdB));


for j=1:length(SNRdB)


sd = sqrt(1/(snr(j)));


h0=(1/(sqrt(2))).*(randn(1,N)+1i.*randn(1,N));%the channel gain of the direct path.

h1=(1/(sqrt(2))).*(randn(1,N)+1i.*randn(1,N));%the channel gain of the first hop in the relay path.

h2=(1/(sqrt(2))).*(randn(1,N)+1i.*randn(1,N));%the channel gain of the second hop in the relay path.

n0=(1/(sqrt(2))).*(randn(1,N)+1i.*randn(1,N));%AWGN in direct path.

n1=(1/(sqrt(2))).*(randn(1,N)+1i.*randn(1,N));%AWGN in the first hop.

n2=(1/(sqrt(2))).*(randn(1,N)+1i.*randn(1,N));%AWGN in the second hop.


% B=1./abs(h1);%Amplification Gain

B=sqrt(snr(j) ./ ((snr(j) .* abs(h1).^2) + 1));


y0=(h0.*Tx)+(sd).*n0;%the received signal in the direct path.

y1=(h1.*Tx)+(sd).*n1;%the received signal in the first hop.

yAmp=B.*y1;%Amplification of y1

y2=h2.*yAmp+(sd).*n2;%received signal in the second hop


y=(conj(h0)./(sd)).*y0+((conj(h1).*conj(h2).*conj(B))./((abs(h2).^2+abs(B).^2+1).*(sd))).*y2;


bHat=real(y)>0.5;%The estimated bit sequence


nErr(j)=size(find(bHat-b),2);%Extract the number of erros between b and bHat

end

BER=nErr./N;%Average BER

figure

semilogy(SNRdB,BER);

title('Amplify-and-forward (AF) relaying of cooperative diversity');

xlabel('Eb/N0, (dB)');

ylabel('BER');

grid on


SIMULATED OUTPUT

DOWNLOAD LINK