clear all
clc
disp('Simulation started');
tic
Eb_N0_dB = -3:20; % Multiple Eb/N0 values
EbN0Lin = 10.^(Eb_N0_dB/10); % Decimal SNR
nErr=zeros(1,length(Eb_N0_dB));
N = 10^4; % Number of bits or symbols
frameSize=16;
ip = rand(1,N)>0.5; % Generate Bits
x = vec2mat(ip,frameSize); % Frame bits
x= padarray(x,[0 3],'post');
Gx= [1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
parfor row=1:N/16
[r(row,:) c(row,:)]= CRC_Chk(x(row,:),Gx);
%r
%[r c]= CRC_Chk(c,Gx);
%r
end
ipCoded=reshape(c',1,[]);
N2=length(ipCoded);
n = 1/sqrt(2)*(randn(1,N2) + 1i*randn(1,N2)); % white gaussian noise, 0dB variance
h=(1/sqrt(2))*((randn(1,N2))+1i*(randn(1,N2))); % Rayleigh channel
s = 2*ipCoded-1;
for ii = 1:length(Eb_N0_dB)
% Noise addition
y = s+ 10^(-Eb_N0_dB(ii)/20)*n; % additive white gaussian noise
%y=conj(h).*y./abs(h).^2;
% receiver - hard decision decoding
ipHat = real(y)>0;
yMat = vec2mat(ipHat,19);
for row2=1:N/16
[r2(row2,:) c2(row2,:)]= CRC_Chk(yMat(row2,:),Gx);
err(row2)= nnz(r2(row2,:));
end
nErr(ii)=nnz(err);
% Counting the errors
end
simBer = nErr/(N/16); % Simulated ber
a1= 1.5833*exp(-EbN0Lin);
a2=2.375*exp(-1.33*EbN0Lin);
theory= a1+a2;
close all
figure
semilogy(Eb_N0_dB,simBer,'b.-');
axis([-3 10 10^-5 1])
grid on
legend('sim');
xlabel('Eb/No, dB');
ylabel('Frame Error Rate');
title('Frame error probability curve for BPSK modulation');
disp('Simulation completed!');
toc
评论0