Vous êtes sur la page 1sur 4

% 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])

% 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





ber = berfading(EbNo,'pam',M,divorder)
ber = berfading(EbNo,'qam',M,divorder)
ber = berfading(EbNo,'psk',M,divorder)
ber = berfading(EbNo,'depsk',M,divorder)
ber = berfading(EbNo,'oqpsk',divorder)
ber = berfading(EbNo,'dpsk',M,divorder)
ber = berfading(EbNo,'fsk',M,divorder,coherence)
ber = berfading(EbNo,'fsk',2,divorder,coherence,rho)
ber = berfading(EbNo,...,K)
ber = berfading(EbNo,'psk',2,1,K,phaserr)
[BER,SER] = berfading(EbNo, ...)
BER for BPSK modulation in a
% Rayleigh fading channel

clear
N = 10^6 % number of bits or symbols

% Transmitter
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0


Eb_N0_dB = [-3:35]; % multiple Eb/N0 values

for ii = 1:length(Eb_N0_dB)

n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white gaussian noise, 0dB
variance
h = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % Rayleigh channel

% Channel and noise Noise addition
y = h.*s + 10^(-Eb_N0_dB(ii)/20)*n;

% equalization
yHat = y./h;

% receiver - hard decision decoding
ipHat = real(yHat)>0;

% counting the errors
nErr(ii) = size(find([ip- ipHat]),2);

end

simBer = nErr/N; % simulated ber
theoryBerAWGN = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber
EbN0Lin = 10.^(Eb_N0_dB/10);
theoryBer = 0.5.*(1-sqrt(EbN0Lin./(EbN0Lin+1)));

% plot
close all
figure
semilogy(Eb_N0_dB,theoryBerAWGN,'cd-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,theoryBer,'bp-','LineWidth',2);
semilogy(Eb_N0_dB,simBer,'mx-','LineWidth',2);
axis([-3 35 10^-5 0.5])
grid on
legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation in Rayleigh channel');


EXP-5

Vous aimerez peut-être aussi