Aim:
To estimate bit error rate in fading channel.

Program:
clc;
clear all;
close all
% Sampling Operation
f=150;%input signal frequency
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');
fs1=10*f;%sampling frequency;
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);
N=4;%Number of bits in PCM
M=2^N;;% Number of levels
s=(vh-vl)/M;%step size parameter
par=vl+s:s:vh-s;% level are between vmin and vmax with difference of del
cb=vl+s/2:s:vh-s/2;% Contaion Quantized valuses
[index,quant]=quantiz(s2,par,cb);% Quantization process
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;
subplot(4,2,5),plot(t3,sint),title('PSK carrier signal'),xlabel('time');ylabel('amplitude');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=h.*psksig+n;% % Channel and Noise addition
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;
SNR=10.^(SNRdB/10);
theoretical_rayleigh=0.5*(1-sqrt(SNR./(1+SNR)));
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);
grid on;
hold on;
semilogy(SNRdB,BER_th,'r','linewidth',2.5);
grid on;
hold on;
semilogy(SNRdB,simBER_rayleigh,'g*-','LineWidth',2);
hold on;
semilogy(SNRdB,theoretical_rayleigh,'ko','LineWidth',2);
hold on
axis([-5 20 10^-2 1.2]);
title('SNR Vs BER for BPSK over AWGN and Rayleigh');
xlabel('SNR');
ylabel('Bit Error Rate or Symbol Error Rate');

Algorithm:
1. Clear all the commands, files from work place.
2. Generate input signal.
3. Sample the input signal
4. Quantize the sampled signal.
5. Generate PCM wave.
6. Convert the discrete PCM signal into binary digits and increase the bandwidth.
7. Generate carrier signal.
8. Generate the PSK signal by multiplying the PCM signal with the carrier signal.
9. Determine the length of the PCM signal.
10. Plot all the graphs.
11. Define the noise signal and find the SNR dB value of noise in AWGN channel.
12. Multiply the AWGN channel noise to PSK signal.
13. Define the noise signal and find the SNR dB value of noise in Rayleigh fading channel.
14. Multiply the Rayleigh fading channel noise to PSK signal.
15. Determine BER of PSK signal Rayleigh fading channel noise environment.
16. Find the BER of PSK signal for theoretical Rayleigh fading channel environment.
17. Determine BER of PSK signal AWGN channel noise environment.
18. Plot the BER of PSK in Rayleigh fading channel (theoretical and simulation) and AWGN
channel.