David83
Advanced Member level 1
AF Cooperative Diversity MATLAB Code
Hi,
I have trouble in programming AF cooperative diversity technique. I have the following MATLAB code, but the result does not match the theoretical results. I assumed that the power at the source is equal to the power at the relay.
Any one knows where is my problem?
Thanks in advance
Hi,
I have trouble in programming AF cooperative diversity technique. I have the following MATLAB code, but the result does not match the theoretical results. I assumed that the power at the source is equal to the power at the relay.
Code:
clear all;
clc
N=10^6;%Number of bits
b=rand(1,N)>0.5;%Generate 0s and 1s
s=2.*b-1;%NRZ
SNRdB=0:2:24;%SNR in dB
for ii=1:length(SNRdB)
d=s;
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
y0=h0.*d+((10.^(-SNRdB(ii)/20))).*n0;%the received signal in the direct path.
y1=h1.*d+((10.^(-SNRdB(ii)/20))).*n1;%the received signal in the first hop.
yAmp=B.*y1;%Amplification of y1
y2=h2.*yAmp+((10.^(-SNRdB(ii)/20))).*n2;%received signal in the second hop
y=(conj(h0)./(10.^(-SNRdB(ii)/20))).*y0+((conj(h1).*conj(h2).*conj(B))./((abs(h2).^2+abs(B).^2+1).*(10.^(-SNRdB(ii)/20)))).*y2;
bHat=real(y)>0.5;%The estimated bit sequence
nErr(ii)=size(find(bHat-b),2);%Extract the number of erros between b and bHat
end
BER=nErr./N;%Average BER
semilogy(SNRdB,BER);
Any one knows where is my problem?
Thanks in advance
Last edited: