154 lines
3.8 KiB
Matlab
154 lines
3.8 KiB
Matlab
useprbs = 1;
|
|
M = 2;
|
|
randkey = 1;
|
|
datarate = 448e9;
|
|
fsym = round(datarate / log2(M)) ;
|
|
|
|
%%%%% PRBS Generation in correct shape for Modulation Format %%%%%%
|
|
O = 16; %O of prbs
|
|
N = 2^(O); %length of prbs
|
|
[~,seed] = prbs(O,1); %initialize first seed of prbs
|
|
bitpattern=[];
|
|
|
|
state = struct();
|
|
|
|
para = struct();
|
|
|
|
if M == 6
|
|
para.bl = 2^(O-2);
|
|
para.dimension = 5;
|
|
else
|
|
para.bl = 2^(O-1);
|
|
para.dimension = log2(M); %2.5bits/sym -> 2 bit/sym
|
|
end
|
|
|
|
para.rand = 0;
|
|
|
|
para.order = floor(O / log2(M));
|
|
para.skip =0;
|
|
para.bruijn = 0;
|
|
para.reset_prms = 0;
|
|
para.method = 1;
|
|
|
|
data_in = [];
|
|
global loop;
|
|
loop = 0;
|
|
[data_out,state_] = prms(data_in, state, para);
|
|
loop = 1;
|
|
[data_out,state_out] = prms(data_in, state_, para);
|
|
bitpattern = data_out';
|
|
|
|
if M == 6
|
|
bitpattern = reshape(bitpattern',[],1);
|
|
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
|
end
|
|
|
|
Tx_bits = Informationsignal(bitpattern);
|
|
|
|
%%%%% Duobinary %%%%%%
|
|
|
|
precode = 1;
|
|
db_encode = 0;
|
|
|
|
close all
|
|
Symbols_tx = PAMmapper(M,0).map(Tx_bits);
|
|
Symbols_tx.fs = fsym;
|
|
|
|
%%% precode
|
|
if precode
|
|
Symbols0 = Duobinary().precode(Symbols_tx);
|
|
else
|
|
Symbols0 = Symbols_tx;
|
|
end
|
|
|
|
figure;histogram(Symbols0.signal);
|
|
|
|
for n = 0:200
|
|
|
|
if db_encode
|
|
Symbols1 = Duobinary().encode(Symbols0);
|
|
else
|
|
Symbols1 = Symbols0;
|
|
end
|
|
|
|
Symbols2 = Symbols1;
|
|
pos = 1;
|
|
if n~=0
|
|
for pos = 1:n
|
|
po = randi(100);
|
|
a = Symbols2.signal(100+pos) == Symbols1.signal(100+po);
|
|
while a == 1
|
|
po = po+1;
|
|
po = randi(100);
|
|
a = Symbols2.signal(100+pos) == Symbols1.signal(100+po);
|
|
end
|
|
Symbols2.signal(100+pos) = Symbols1.signal(100+po);
|
|
end
|
|
end
|
|
|
|
% disp(Symbols2.signal(100:100+pos)==Symbols1.signal(100:100+pos))
|
|
|
|
%%% encode
|
|
|
|
if db_encode
|
|
|
|
% figure;histogram(Symbols2.signal);
|
|
|
|
Symbols3 = Duobinary().decode(Symbols2);
|
|
% figure;histogram(Symbols3.signal);
|
|
% autoArrangeFigures;
|
|
elseif precode
|
|
Symbols3 = Duobinary().encode(Symbols2);
|
|
Symbols3 = Duobinary().decode(Symbols3);
|
|
% figure;histogram(Symbols3.signal);
|
|
else
|
|
Symbols3 = Symbols2;
|
|
end
|
|
|
|
Rx_bits = PAMmapper(M,0).demap(Symbols3);
|
|
|
|
%%%%% Check BER of Bit Sequence %%%%%%
|
|
|
|
[~,error_num(n+1),ber,error_pos] = calc_ber(Tx_bits.signal,Rx_bits.signal,"skip_front",10,"skip_end",10,"returnErrorLocation",1);
|
|
|
|
% disp(['BER: ',sprintf('%.1E',ber),sprintf(' - Num. Err: %.1d',error_num(n+1)-2),' - - PAM-',num2str(M)]);
|
|
fprintf('n: %d - Num. Err: %.1d \n',n,error_num(n+1));
|
|
end
|
|
|
|
|
|
figure()
|
|
hold on
|
|
scatter(1:length(Symbols3),Symbols3.signal,1,'.');
|
|
scatter(error_pos,Symbols3.signal(error_pos),14,'o');
|
|
|
|
|
|
figure(3);
|
|
clf
|
|
%sgtitle(['BER: ',num2str(ber),' // Error is at position: ',num2str(error_pos),''])
|
|
subplot(2,2,1)
|
|
hold on
|
|
title('First Bits')
|
|
stairs(Tx_bits.signal(1:100,1),'LineStyle','-','LineWidth',2,'DisplayName','Tx Bits');
|
|
stairs(Rx_bits.signal(1:100,1),'LineWidth',2,'DisplayName','Rx Bits','LineStyle',':')
|
|
legend
|
|
|
|
subplot(2,2,2)
|
|
title('Last Bits')
|
|
hold on
|
|
stairs(Tx_bits.signal(end-50:end,1),'LineStyle','-','LineWidth',2,'DisplayName','Tx Bits');
|
|
stairs(Rx_bits.signal(end-50:end,1),'LineWidth',2,'DisplayName','Rx Bits','LineStyle',':')
|
|
legend
|
|
|
|
subplot(2,2,3)
|
|
hold on
|
|
title('First Symbols Compare')
|
|
stairs(Symbols_tx.signal(1:100,1),'LineWidth',2,'DisplayName','Tx Symbols','LineStyle','-')
|
|
stairs(Symbols.signal(1:100,1),'LineStyle',':','LineWidth',2,'DisplayName','Rx Symbols');
|
|
legend
|
|
|
|
subplot(2,2,4)
|
|
hold on
|
|
title('Last Symbols Compare')
|
|
stairs(Symbols_tx.signal(end-50:end,1),'LineWidth',2,'DisplayName','Tx Symbols','LineStyle','-')
|
|
stairs(Symbols.signal(end-50:end,1),'LineStyle',':','LineWidth',2,'DisplayName','Rx Symbols');
|
|
legend |