119 lines
2.7 KiB
Matlab
119 lines
2.7 KiB
Matlab
|
|
|
|
%%%%% SETTINGS %%%%%%
|
|
useprbs = 1;
|
|
M = 8;
|
|
randkey = 1;
|
|
fsym = 112e9;
|
|
viewresults = 0;
|
|
|
|
%%%%% Mapping %%%%%
|
|
M = 8;
|
|
data = 0:M-1;
|
|
bitpersymbol = log2(M);
|
|
|
|
%Bits
|
|
bits = int2bit(data,bitpersymbol, true);
|
|
|
|
%Integers
|
|
ints = bit2int(bits,bitpersymbol, true);
|
|
|
|
Tx_bits = Informationsignal(bits');
|
|
Digi_Mod = PAMmapper(M,0);
|
|
Symbols = Digi_Mod.map(Tx_bits);
|
|
moveitgray = Symbols.signal;
|
|
|
|
%Gray Symbol Mapping
|
|
matlabgray = pammod(ints,M,0,'gray');
|
|
scaling_factor = rms(unique(matlabgray));
|
|
matlabgray = matlabgray ./ scaling_factor;
|
|
|
|
|
|
%Demod
|
|
moveitgray = moveitgray.* scaling_factor;
|
|
matlabgray = matlabgray .* scaling_factor;
|
|
ints_demap = pamdemod(matlabgray,M,0,'gray');
|
|
|
|
bits_demap = int2bit(ints_demap,bitpersymbol, true);
|
|
|
|
% for i = 1:M
|
|
% fprintf('%d , %d , %d --> %d \n',bits(1,i),bits(2,i),bits(3,i),matlabgray(i));
|
|
% end
|
|
%
|
|
% for i = 1:M
|
|
% fprintf('%d , %d , %d --> %d \n',bits(1,i),bits(2,i),bits(3,i),moveitgray(i));
|
|
% end
|
|
|
|
scatterplot(matlabgray,1,0,'b*');
|
|
for k = 1:M
|
|
text(real(matlabgray(k)),imag(matlabgray(k))+0.6,num2str(ints_demap(k)),"Color",[1 1 1]);
|
|
|
|
text(real(matlabgray(k)),imag(matlabgray(k))-1.6,num2str(bits(:,k)),"Color",'blue');
|
|
text(real(moveitgray(k)),imag(moveitgray(k))-3,num2str(bits(:,k)),"Color",'green');
|
|
end
|
|
axis([-M M -3 2])
|
|
|
|
|
|
symbols = bit2int(bitGroups',bitpersymbol, true);
|
|
|
|
|
|
%%%%% PRBS Generation in correct shape for Modulation Format %%%%%%
|
|
O = 10; %order of prbs
|
|
N = 2^(O-1); %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);
|
|
|
|
%%%%% ACTUAL TEST: Back to Back Mapping: Bits -> Symbols and Symbols -> Bits %%%%%%
|
|
|
|
Digi_Mod = PAMmapper(M,0);
|
|
|
|
symbols = bitMapper(bitpattern, M, 'PAM');
|
|
|
|
|
|
Symbols = Digi_Mod.map(Tx_bits);
|
|
|
|
Rx_bits = PAMmapper(M,0).demap(Symbols);
|
|
|
|
|
|
%%%%% VALIDATION: BER is required to be zero %%%%%%
|
|
|
|
[~,error_num,ber,error_pos] = calc_ber(Tx_bits.signal,Rx_bits.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
|
|
|
|
|
%%%%% For User: Show Debug Info and Results %%%%%%
|
|
|
|
if viewresults
|
|
disp(['BER: ',sprintf('%.1E',ber),' - - PAM-',num2str(M)]);
|
|
|
|
|
|
figure
|
|
subplot(1,2,1)
|
|
hold on
|
|
title('Symbols Out')
|
|
stairs(Symbols_tx.signal(1:100,1),'LineWidth',2,'DisplayName','Tx Symbols')
|
|
legend
|
|
grid
|
|
subplot(1,2,2)
|
|
u = unique(Symbols_tx.signal);
|
|
scatter(0,u,'filled','o','LineWidth',2,'MarkerFaceColor',linspecer(1));
|
|
grid
|
|
end
|
|
|
|
|