77 lines
2.1 KiB
Matlab
77 lines
2.1 KiB
Matlab
useprbs = 1;
|
|
M = 6;
|
|
randkey = 1;
|
|
datarate = 448e9;
|
|
fsym = round(datarate / log2(M)) ;
|
|
|
|
%%%%% PRBS Generation in correct shape for Modulation Format %%%%%%
|
|
O = 17; %order of prbs
|
|
N = 2^(O); %length of prbs
|
|
[~,seed] = prbs(O,1); %initialize first seed of prbs
|
|
bitpattern=[];
|
|
|
|
if useprbs
|
|
for i = 1:log2(M)
|
|
[bitpattern(:,i),seed] = prbs(O,N,seed);
|
|
end
|
|
else
|
|
s = RandStream('twister','Seed',randkey);
|
|
for i = 1:log2(M)
|
|
bitpattern(:,i) = randi(s,[0 1], N, 1);
|
|
end
|
|
end
|
|
|
|
if M == 6
|
|
bitpattern = reshape(bitpattern,[],1);
|
|
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
|
end
|
|
|
|
Tx_bits = Informationsignal(bitpattern);
|
|
|
|
Symbols_tx = PAMmapper(M,0).map(Tx_bits);
|
|
Symbols_tx.fs = fsym;
|
|
|
|
Symbols = Duobinary().precode(Symbols_tx);
|
|
|
|
Symbols = Duobinary().encode(Symbols);
|
|
|
|
Symbols = Duobinary().decode(Symbols);
|
|
|
|
Rx_bits = PAMmapper(M,0).demap(Symbols);
|
|
|
|
[~,error_num,ber,error_pos] = calc_ber(Tx_bits.signal,Rx_bits.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
|
|
|
disp(['BER: ',sprintf('%.1E',ber),' - - PAM-',num2str(M)]);
|
|
%
|
|
|
|
|
|
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 |