Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AF Cooperative Diversity MATLAB Code Needed

Status
Not open for further replies.

David83

Advanced Member level 1
Advanced Member level 1
Joined
Jan 21, 2011
Messages
410
Helped
45
Reputation
92
Reaction score
45
Trophy points
1,308
Activity points
3,639
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.

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:

Re: AF Cooperative Diversity MATLAB Code

hi,

i have question ...i am doing my project on cooperative communication in cdma..

and for power allocation algorithm i am using Amplify and forward protocol...here you have used the AF protocol with equal gain ...

i am confused if i want to use different gain for source to relay and relay to receiver...how to implement this...please guide me

Thanks In advance
 

Re: AF Cooperative Diversity MATLAB Code

your problem seems about amplification gain. since there is an addition noise too at received signal at the relay; amplication gain should be
B=1./sqrt(No+abs(hsr).^2)
 

Re: AF Cooperative Diversity MATLAB Code

Here is the correct code:

clear all; close all; clc;
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 ii=1:length(SNRdB)

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

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(ii) ./ ((snr(ii) .* 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(ii)=size(find(bHat-b),2);%Extract the number of erros between b and bHat
end
BER=nErr./N;%Average BER
semilogy(SNRdB,BER);
grid on
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top