Understanding Matlab code - opensource matlab code.

1 view (last 30 days)
Hi ,
I'm trying to write this matlab code as shown here below and to plot the graphs as shown in below with matlab code implementation shown aswell:
#first
#second
#third - output of the matlab code that's mentioned above:
Unfortuantely when I write the matlab code as mentioned above in first two photos I'm not suceeding to plot the graph as suggested in third photo, can anyone please help me what's wrong with the code? I'm trying exactly to write the matlab code that's mentioned in first two photo and I didn't succeed to run the code successfully .. can please anyone help me on this if he succeed to run the code properly to get the graph that's mentioned in third photo?
Appreciated to attach the code that's used to be more clear and understandable.
Thanks much!
  8 Comments
Walter Roberson
Walter Roberson on 13 Mar 2022
%EbN0dB=input("PLZ ENTER Initial Eb/No (dB) = ");
EbN0dB=-20
EbN0dB = -20
t=1;
for i=1:1:50
R=4/7; %K=4 and n=3 using Hamming as encoding codes and decoding to overcome errors;
EbN0=10^(EbN0dB/10);
sigma=sqrt(1/(2*R*EbN0)); % EbNo=1/2R(sigma)^2
k=4; % Message Bits
n=7; % Total Number of Bits
cwords=[0 0 0 0 0 0 0;
0 0 0 1 0 1 1;
0 0 1 0 1 1 0;
0 0 1 1 1 0 1;
0 1 0 0 1 1 1;
0 1 0 1 1 0 0;
0 1 1 0 0 0 1;
0 1 1 1 0 1 0;
1 0 0 0 1 0 1;
1 0 0 1 1 1 0;
1 0 1 0 0 1 1;
1 0 1 1 0 0 0;
1 1 0 0 0 1 0;
1 1 0 1 0 0 1;
1 1 1 0 1 0 0;
1 1 1 1 1 1 1];
Nerrs=0; Nblocks=10000;
for i = 1:Nblocks
msg=randi([0,1],1,k);
%**************Encoding*******************************
cword=[msg mod(msg(1)+msg(2)+msg(3),2)...
mod(msg(2)+msg(3)+msg(4),2)...
mod(msg(1)+msg(2)+msg(4),2)];
s=1-2*cword; % BPSK bit to symbol conversion mapping
r= s+sigma*randn(1,n); % AWGN CHANNEL rand(1,n) adding guassian noise of variance 1
% ************Hard Decoding*****************
b=(r<0); % Thresholg at Zero best for bpsk demod
dist= mod(repmat(b,16,1)+cwords,2)*ones(7,1);
[mind1,pos]=min(dist);
msg_cap1=cwords(pos,1:4);
%***************Soft Decoding******************
corr=(1-2*cwords).*r;
[mind2,pos]=max(corr);
msg_cap2=cwords(pos,1:4);
Nerrs=Nerrs+sum(msg~=msg_cap1); % Total Errors
end
BER_sim(t)=Nerrs/k/Nblocks; %Bit Error Rate Calculation
%**** QoS Varifying and Updating to Transmitter *******
if(Nerrs>2000)
%disp('Increasing SNR ');
EbN0dB=EbN0dB+1;
else EbN0dB=EbN0dB-1;
%disp('Decreasing SNR ');
end
%disp([EbN0dB R BER_sim(t) Nerrs k*Nblocks]);
y(t)=10*log(BER_sim(t)); %log BER
t=t+1;
end
x=1:1:50;
plot(x,BER_sim,'ro');
title(' BER PLOT');
xlabel('Iterations Adapting EbNo');
ylabel('BER(dB)');
legend('Adaptive EbNo');
grid on;
Jimmy cho
Jimmy cho on 13 Mar 2022
@AndresVar by the way I need you to do that on purpose which the idea and the concept that's behind the code will be really explicit and then I can explain to you by the two explames the purpose and the logic behind ..
it's really wonderful.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!