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.

Flat fading of BPSK simulation

Status
Not open for further replies.

lincolndsp

Banned
Joined
Aug 13, 2005
Messages
71
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Location
Ukraine
Activity points
0
raylrnd +matlab+standard deviation

Guys, help me understand why in my matlab code below the
BER I get is better than it should be (for coherent BPSK). Maybe I add noise not
to the proper sognal or maybe parameter B in raylrnd is improper.

%MATLAB code
N=10000;%number of bits
s1 = zeros(N*100,1)';%1st path
s2 = zeros(N*100,1)';%2ndpath
EbNo=20;% Eb/No in dB
scar=zeros(2,100*N);
a=(sign(rand(1,N)-0.5)+1)/2;%generating random sequence of bits
T=1%bit interval
t=0:0.01*T:N*T-0.01*T;
%time

BB=1.2; % parameter in the Rayleigh envelope function raylrnd

f=2% carrier frequency
scar(1,:)=sin(2*pi*f*t);% the 2 reference signals at the receiver
scar(2,:)=-sin(2*pi*f*t);

randn('state',123)
ab = raylrnd(BB,1,N*100); %Raylegh envelope
rand('state',234)
phi=unifrnd(0,2*pi,1,N*100); %uniform phase

for k=1:size(a,2)
i=1;
for j=(k-1)*100+1:k*100
if (a(k)+1)==1
s1(j)=ab(i).*sin(2*pi*f*t(i)+phi(i));
end;
if (a(k)+1)==2
s1(j)=-ab(i).*sin(2*pi*f*t(i)+phi(i));
end;
i=i+1;
end;
end;


randn('state',1230)
ab = raylrnd(BB,1,N*100);
rand('state',1234)
phi=unifrnd(0,2*pi,1,N*100);

for k=1:size(a,2)
i=1;
for j=(k-1)*100+1:k*100
if (a(k)+1)==1
s2(j)=ab(i).*sin(2*pi*f*t(i)+phi(i));
end;
if (a(k)+1)==2
s2(j)=-ab(i).*sin(2*pi*f*t(i)+phi(i));
end;
i=i+1;
end;
end;








s = zeros(1,N*100);

for k=1:size(a,2)
i=1;
for j=(k-1)*100+1:k*100
s(j)=scar(a(k)+1,i); %bpsk signal
i=i+1;
end;
end;
sorig=s;% save bpsk signal for future purpose of noise addition

gmsksig=zeros(N*100,1)';
bpsksig=sorig;

SNR=-20+EbNo+3;% SNR in dB, +3dB is because adding noise to a real signal,
%not complex

snoise = zeros(N*100,1)';
noise = zeros(N*100,1)';
snoise=awgn(bpsksig,SNR,'measured',123,'dB');
snoise1 = zeros(N*100,1)';
noise1 = zeros(N*100,1)';
noise=snoise-sorig;

snoise1=awgn(bpsksig,SNR,'measured',1234,'dB');
noise1=snoise1-sorig;

snoise2=awgn(bpsksig,SNR,'measured',234,'dB');
noise2=snoise2-sorig;


s=s1+s2+noise+noise1; %2 paths faded

%correlator detector coherent

tt=0:0.01*T:T-0.01*T;
sinerom = zeros(100,2)';
cosintegral=zeros(N,2,100);
cossum=zeros(N,2);
sinerom(1,:)=sin(2*pi*f*tt);%signal copy of sine representing '1'
sinerom(2,:)=-sin(2*pi*f*tt);%signal copy of sine representing '-1' with inverted phase
for k=1:size(a,2)
for i=1:2
for jj=1:100
cosintegral(k,i,jj)=s((k-1)*100+jj).*sinerom(i,jj); % here correlation-type detector
end; % is realized ; first multiplying the received signal
%with signal copies in the 2 branches of
%correlator
end;
end;
j=0;
for k=1:size(a,2)
for i=1:2
cossum(k,i)=sum(cosintegral(k,i,:)); % here is integration or just sum of th samples
end;
maxcossum(k)=max(cossum(k,:)); % here max value of the correlator branches is determined
end;
for k=1:size(a,2)
for i=1:2
if cossum(k,i)==maxcossum(k)
indexcossum(k)=i; %here the number of the branch where maximum
% is achieved (1 or 2)
end;
end;
end;
atrsec=[0 1];
for k=1:size(a,2)
adetsec(k)=atrsec(indexcossum(k)); % the 1st branch means '1' has been transmitted
end; % the 2nd branch means '-1' has been transmitted

for j=1:size(a,2)
res(j)=adetsec(j)-a(j);
end;
max(res)
min(res)
kjk=0;
for j=1:size(a,2)
if res(j)==0
kjk=kjk+1;
end;
end;
errornum=size(a,2)-kjk %number of errors
format short e;
bercalc=errornum/size(a,2) %BER
format;
%end

The attached m-file is the same. These emotions symbols made me do
this.
 

ee 252 - spring 2004 - san jose state university

Check this code:

% Simulation of BPSK over a flat Rayleigh fading channel
% EE 252 - Spring 2004 - San Jose State University
clear

N=1000000;
snr=0:1:25;
for m=1:size(snr,2)
efade = 0;
egaus = 0;
No=10^(-snr(m)/10); % PSD of AWGN
sigma= sqrt(No/2); % Standard deviation
for n=1:N
s=(-1)^round(rand);
x=randn/sqrt(2);
y=randn/sqrt(2);
p=x^2 + y^2; % Fading Power
a=sqrt(p); % Fading Amplitude
r=a*s + sigma*randn; % faded signal + AWGN
rg = s + sigma*randn; % unfaded signal + AWGN
if (r>0)
shat=+1;
else
shat=-1;
end
if (rg>0)
sh=+1;
else
sh=-1;
end
if (shat ~= s)
efade = efade + 1;
end
if (sh ~= s)
egaus = egaus + 1;
end
end
pe(m)=efade/N; % BER flat Rayleigh fading
peg(m)=egaus/N; % BER AWGN only
fprintf('%f \t %e\n',snr(m),pe(m));
end
semilogy(snr,pe,'-')
hold on
semilogy(snr,peg,':')
legend('Rayleigh channel','AWGN channel');
ylabel('Bit Error Rate');
xlabel('Average E_b/N_0 (dB)');
title('Perfomance of BPSK over flat-Rayleigh and AWGN channels');
axis([ snr(1) snr(end) 9.5e-6 1])
 

    lincolndsp

    Points: 2
    Helpful Answer Positive Rating
simulation rand()*(n-1)+1

to ahmedseu:
thank you. please could you
also post similar matlab code
for frequency-selective fading
for example the basic the two-ray
Rayleigh fading
 

bpsk awgn flat fading matlab simulation

% Simulation of the error performance of BPSK modulation over a symbol-spaced
% slow frequency-selective two-path Rayleigh fading channel
% EE 252 - Spring 2004 - San Jose State University
clear all
clc

p(1) = input('Enter the first element of the power delay profile in dB: ');
p(2) = input('Enter the second element of the power delay profile in dB: ');

P1 = 10^(p(1)/10);
P2 = 10^(p(2)/10);
PM = P1 + P2;

p_n=P1; %/PM
p_n_1=P2; %/PM

N=10000;
snr=0:1:25
for m=1:size(snr,2)
efade = 0;
No=10^(-snr(m)/10); % PSD of AWGN
sigma= sqrt(No/2); % Standard deviation
s_n_1 = 0;
a_n_1 = 1;
for n=1:N
s=(-1)^round(rand);
x=randn/sqrt(2);
y=randn/sqrt(2);
p=x^2 + y^2; % Fading Power
a=sqrt(p); % Fading Amplitude
r_n = sqrt(p_n)*a*s + sqrt(p_n_1)*a_n_1*s_n_1;
a_n_1 = a;
s_n_1 = s;
r=r_n + sigma*randn; % faded signal + AWGN
if (r>0)
shat=+1;
else
shat=-1;
end
if (shat ~= s)
efade = efade + 1;
end
end
pe(m)=efade/N; % BER
fprintf('%f \t %e\n',snr(m),pe(m));
end

semilogy(snr,pe,':s')
ylabel('Bit Error Rate');
xlabel('Average E/N_0 (dB)');
title('Perfomance of BPSK modulation over a two-path Rayleigh channel');
axis([ snr(1) snr(end) 1e-3 1])
grid on
hold on
 

    lincolndsp

    Points: 2
    Helpful Answer Positive Rating
simulating flat fading noise awgn

Asalm alikm
could you please post similar matlab code
BPSK over awgn channel

Added after 0 seconds:

Asalm alikm
could you please post similar matlab code
BPSK over awgn channel
 

flat fading simulation

Pl. post the codes for digffeerent coding schemes suitable for cdma.
 

Hi
Can anybody post QAM-COFDM matlab code for
(1)Raleigh frequency selective & flat fading
(2)Simillarly for Ricean fading

Thanx in advance.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top