The following is a code for BCH code in AWGN for BPSK modulation. What seems to be the problem with it? I don't seem to be getting with coding and without coding graph
2 views (last 30 days)
Show older comments
Here's the code:
clc;
clear all;
close all;
tic;
N = 10000
% % Generate Data Stream
data = randint(1,N);
datalen = length(data);
% bch encoding
fragments = reshape(data,250,N/250);
fragrows = fragments';
fragrowsgf = gf(fragrows,1);
doublefrags = fragrowsgf.x;
encodedbitstream = [];
a=[];
for i = 1:(N/250)
b = bchenc(fragrowsgf(i,:),511,250);
c=double(b.x);
encodedbitstream=[encodedbitstream;c];
end
encodedcolumn = reshape(encodedbitstream',511*(N/250),1);
encodedrow = encodedcolumn';
encodelength = length(encodedrow);
% % Convert Equvalent Antipodal
bipolar = 2*encodedrow-1;
% % carrier
t=0:.2:(1-0.01);
car = cos(2*pi*t)./(norm(cos(2*pi*t)));
len = length(car);
bipolarexpand = kron(bipolar,ones(1,len));
snrdb = 0:14;
snr = 10.^(snrdb./10);
sdev = sqrt(1./(2.*snr));
snrlen = length(snr);
carrier = (repmat(car,snrlen,encodelength));
noise = [];
noise = (diag(sdev)*randn(snrlen,len*encodelength));
rcv= [];
bipolarstack = repmat(bipolarexpand,snrlen,1);
% % Modulate The Carrier
trans = carrier.*bipolarstack;
% % Received With Awgn
rcv = (trans+noise);
corrinput = carrier.*rcv;
corrinput1 = corrinput';
inter1 = reshape(corrinput1,len,snrlen*encodelength);
interestimate = (sum(inter1));
% % result after passing correlator
estimate = reshape(interestimate,encodelength,snrlen);
% % Detect the received bits
rcvbits = estimate>0;
rcvgf = gf(rcvbits,1);
d=[];
e=[];
f=[];
g=[];
h=[];
;
for i= 1:snrlen
k=[]
d = rcvgf(:,i);
e = reshape(d,511,N/250);
for j = 1:40
f = bchdec((e(:,j))',511,250);
g=double(f.x);
k=[k g];
end
h = [h;k];
end
% % Bit error rate calculation
ber = xor(h',kron(data',ones(1,snrlen)));
bertotal = sum(ber)./datalen;
semilogy(snrdb,bertotal,'-*r');
hold on;
thber = qfunc(sqrt(2*snr));
semilogy(snrdb,thber);
xlabel('S/N');
ylabel('Bit Error Rate ');
grid on;
t=toc;
x= num2str(t);
title({'Bit Error Rate Performance of BPSK in AWGN, Elapsed time is ' x 'seconds'});
I am getting something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/824760/image.jpeg)
I am looking for something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/824765/image.jpeg)
0 Comments
Answers (0)
See Also
Categories
Find more on BPSK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!