www.pudn.com > Rayleigh.rar > Rayleigh.m


clear; 
close all; 
R=1; 
L=100000; 
for m=1:1:4 
	Eb_No_dB=(m-1)*10; 
	Eb_No=10^(Eb_No_dB/10); 
	SNR=Eb_No*R; 
	std_dev=sqrt(1/SNR/2);%define the power of noise 
     
    %%%%%%%%Transmitter%%%%%%%%%%%%% 
	c=randint(1,L);%generate random binary sequence 
	x=2*c-1;%BPSK modulation 
     
	%%%%%%%%Fading channel%%%%%%%%%%%%%%%%% 
	h=(randn(1,L)+j*randn(1,L))/sqrt(2);%Generate Fading coefficients 
	n=std_dev*(randn(1,L)+j*randn(1,L));%Generate noise sequence 
     
	%%%%%%%Receiver%%%%%%%%%%%%%%%%% 
	y=h.*x+n;%Fading 
	x_hat=sign(   real(  conj(h).*y  )   );%Matched filtering and hard decision 
	c_hat=(x_hat+1)/2;%Demodulation of BPSK 
     
    %%%%%%%Count the Bit errors%%%%%%%%%%%%%%%%% 
	BE(m)=sum(abs(c-c_hat));%Count the Bit errors 
end 
BER=BE/L;%compute the BER 
m=1:1:4; 
semilogy((m-1)*10,BER);%Plot BER curve (simulated) 
hold on; 
grid on; 
 
SNR=10.^((m-1)*10/10); 
BEP=0.5*(1-sqrt(SNR./(1+SNR))); 
semilogy((m-1)*10,BEP,'--r');%Plot the theotetical bit error probability 
xlabel('Eb/No (dB)'); 
ylabel('BER');