



O = 10; %order of prbs
N = 2^(O-1); %length of prbs
[~,seed] = prbs(O,1); %initialize first seed of prbs
bitpattern=[];
M=6;

for i = 1:log2(M)
    [bitpattern(:,i),seed] = prbs(O,N,seed);
end

if M == 6
    bitpattern = reshape(bitpattern,[],1);
end

% [bitpattern,seed] = prbs(O,N,seed);
% % 
% bitpattern = bitpattern';

% 2 ) Build Inf. signal class
bits = Informationsignal(bitpattern);


% 3) Digi modulation -> PAM-M signal
digimod_out     = PAMmapper(M,0).map(bits);

Rx_Bits         = PAMmapper(M,0).demap(digimod_out);

[~,errors_bm,BER,errors] = calc_ber(Rx_Bits.signal,bitpattern,"skip_front",0,"skip_end",0,"returnErrorLocation",1);

formatted_ber = sprintf('%.1e', BER);
disp(['BER: ',formatted_ber]);
            