Rayleigh Fading PDF
Rayleigh Fading PDF
Rayleigh Fading PDF
% IN FADING CHANNEL
clc;
clear all;
close all
%% Sampling Operation
t=0:0.0001:4/f;
sig1=sin(2*3.14*f*t);
subplot(4,2,1);plot(t,sig1);title('message signal');xlabel('time');ylabel('amplitude');
t=1/fs1;
Ts=0:t:4/f;
s2=sin(2*3.14*f*Ts);
subplot(4,2,2);stem(Ts,s2);title('sampled signal');xlabel('samples');ylabel('amplitude');
vh=max(s2);vl=min(s2);
par=vl+s:s:vh-s;% level are between vmin and vmax with difference of del
subplot(4,2,3);stairs(quant);title('quantized signal');xlabel('time');ylabel('amplitude');
%% Encoding Process
codesig=de2bi(index,'left-msb');
codesig=codesig(:);
tt=0:N*length(s2)-1;
subplot(4,2,4);stairs(tt,codesig);xlabel('time');ylabel('amplitude');title('PCM signal');
axis([0 30 -2 2]);
n = length(codesig);
t3 = 0:.01:n;
for i = 1:n
if (codesig(i) == 0)
b_p(i) = -1;
else
b_p(i) = 1;
end
for j = i:.1:i+1
bw((i*100:(i+1)*100)) = b_p(i);
end
end
bw = bw(100:end);
sint = sin(2*pi*1*t3);
psksig = bw.*sint;
axis([1 30 -2 +2]);
subplot(4,2,6);plot(t3,psksig),title('PSK signal'),xlabel('time');ylabel('amplitude');
axis([1 30 -2 +2]);
%% Rayleigh Fadding
num_bit=length(psksig);
SNRdB=-5:2:20;
simBER_rayleigh=zeros(1,length(SNRdB));
for k=1:length(SNRdB)
noise=1/sqrt(2)*(randn(1,num_bit)+1i*randn(1,num_bit));
h=1/sqrt(2)*(randn(1,num_bit)+1i*randn(1,num_bit));
n = noise*10^(-SNRdB(k)/20);
y_rayleigh_cap = y_rayleigh./h;
r_rayleigh = real(y_rayleigh_cap)>0;
simBER_rayleigh(k) = sum(xor(bw,r_rayleigh));
end
simBER_rayleigh=simBER_rayleigh/num_bit; % Simulation
SNR=10.^(SNRdB/10);
theoretical_rayleigh=0.5*(1-sqrt(SNR./(1+SNR))); % Theoritical
num_bit=length(psksig);
SNRdB=-5:2:20;
for k=1:length(SNRdB)
y=awgn(psksig,SNRdB(k));
error=0;
for c=1:1:num_bit
if (psksig(c)==0)&&y(c)>0.5||psksig(c)==1&&(y(c)<0.5)
error=error+1;
end
end
error=error/num_bit;
m(k)=error;
end
SNR=10.^(SNRdB/10);
BER_th=0.5*erfc(sqrt(SNR));
figure
semilogy(SNRdB,m,'*','linewidth',2.5); % Error
grid on;
hold on;
grid on;
hold on;
semilogy(SNRdB,simBER_rayleigh,'g*-','LineWidth',2); % Simulation
hold on;
semilogy(SNRdB,theoretical_rayleigh,'ko','LineWidth',2);% Theoritical
hold on
legend('Error', 'BER in AWGN Channel', 'BER in Rayleigh Fading Channel (Simulation)', 'BER in
Rayleigh Fading Channel (Theoritical)')
xlabel('SNR');