I've written my own code for generation of pseudo-random sequence generation as shown below
function c = GeneratePRS(cinit,N)% This function implements Pseudo-random sequence as specified in
% subclause 5.2.1 of 3GPP TS 38.211 version 15.8.0 Release 15.
%
% INPUTS:
% N = Real valued scalar specifying number of bits to be generated
% cinit = Real-valued scalar specifying initial value for PRBS generator
% OUTPUT:
% c = Real valued vector of length M specifying pseudo-random
% sequence
% Check Input Arguments
if nargin<2 || isempty(N) error('Missing input argument: Please specify MPN');endif nargin<1 || isempty(cinit) cinit = zeros(1,31);end LENGTH_GOLD_SEQ = 31; % Length of Gold Sequence
Nc = 1600; % Shift, Sequence offset from initial time
% Intial value of x1 register
x1_init = 1;% Intial value of x2 register
x2_init = flip(double((dec2bin(cinit,31) ~= '0')));% Preallocating memory for x1 and x2 register
x1 = zeros(1,Nc + N + LENGTH_GOLD_SEQ);x2 = x1;x1(1) = x1_init;x2(1:LENGTH_GOLD_SEQ) = x2_init;for n = 1:(N + Nc) % Generate the x1(n) m-sequence
x1(n + LENGTH_GOLD_SEQ) = mod(x1(n + 3) + x1(n),2); % Generate the x2(n) m-sequence
x2(n + LENGTH_GOLD_SEQ) = mod(x2(n + 3) + x2(n + 2) + x2(n + 1) + x2(n),2);end% Generate the resulting sequence (Gold Sequence) : c()
c = mod(x1((1:N) + Nc) + x2((1:N) + Nc),2);
For comparing it with MATLAB inbuilt function I tested it as
N = 100; % Number of sample in a sequence
cinit = 1023; % cinit value
% Calling my function for generating sequence
myseq = GeneratePRS(cinit,N);cinitvec = double(dec2bin(cinit,31)~='0');% Using Communication Toolbox
seq = comm.GoldSequence('FirstPolynomial', [1 zeros(1,27), 1 0 0 1], ... 'SecondPolynomial', [1 zeros(1,27) 1 1 1 1], ... 'FirstInitialConditions', [zeros(1,30) 1], ... 'SecondInitialConditions', cinitvec, ... 'Shift', 1600, ... 'SamplesPerFrame', N);commseq = (seq())';M = sum(double(myseq == commseq));if M == N disp('Matches');else disp('Error');end% Using 5G Toolbox Function
seq5g = nrPRBS(cinit,N);M = sum(double(myseq == seq5g));if M == N disp('Matches');else disp('Error');end
On Execution I get these results
Matches
Error
Where is the mistake? As Coomunication toolbox matches whereas 5g Toolbox doesn't.
Thanks
Best Answer