Why there is a mismatch in nrPRBS and my custom made pseudo-random sequence generator function?

조회 수: 10 (최근 30일)
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');
end
if 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

채택된 답변

Sriram Tadavarty
Sriram Tadavarty 2020년 3월 12일
Hi Ashish,
The mismatch you observed between the outputs of nrPRBS and the custom written code is due to the comparison of variables having different vector dimensions while calculating M. The generated sequence 'myseq' is a row vector (1 x 100), whereas the output of nrPRBS function 'seq5g' is a column vector (100 x 1). Once the calculation is performed with the same dimensions, the outputs match.
In the testing code, If this line of code M = sum(double(myseq == seq5g)); is modified with sum(double(myseq == seq5g'));. The outputs match. It is similar to what is performed for variable commseq in your testing code.
Hope this helps.
Regards,
Sriram

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 5G Toolbox에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by