1 ## Copyright (C) 2006 Muthiah Annamalai <muthiah.annamalai@uta.edu>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## This function generates the output bits from the PRBS
17 ## state, for the number of iterations specified.
19 ## First argument is the PRBS structure obtained from prbs_generator.
20 ## PRBS iterations is specified in the second argument.
21 ## PRBS start state is taken from the prbs.sregs.
23 ## Second argument of the output is PRBS structure with a new
24 ## state. This allows usage like:
26 ## [ seq, prbs ] = prbs_iterator( prbs, niterations );
28 ## while the state of the PRBS is updated.
30 ## Example: If you had a PRBS shift register like the diagram
31 ## below with 4 registers we use representation by polynomial
32 ## of [ 1 2 3 4], and feedback connections between [ 1 3 4 ].
33 ## The output PRBS sequence is taken from the position 4.
35 ## +---+ +----+ +---+ +---+
36 ## | D |----| D |---| D |---| D |
37 ## +---+ +----+ +---+ +---+
40 ## [+]---------------+------+
41 ## 1 + 0.D + 1.D^2 + 1.D^3
43 ## The code to implement this PRBS will be
44 ## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]);
45 ## x = prbs_iterator(prbs,15)
47 ## See Also: This function is to be used along with functions
48 ## prbs_iterator, prbs_generator and prbs_sequence.
50 function [outputseq, prbs] = prbs_iterator (prbs, iterations = 2^(prbs.reglen)-1)
52 if ( nargin < 1 || nargin > 2 )
55 outputseq=zeros(1,iterations);
56 nstate=zeros(1,prbs.reglen);
58 ## For each iteration, shift the output bit. Then compute the xor pattern of connections.
59 ## Finally apply feedback the stuff. Insert the computed pattern.
62 outputseq(itr)=prbs.sregs(prbs.reglen);
64 ## compute the feedback.
65 for itr2=1:prbs.conlen
67 L=length(prbs.connections{itr2});
69 val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3)));
71 nstate(prbs.connections{itr2}(1))=val;
74 ## rotate the output discarding the last output.
75 prbs.sregs=[0 prbs.sregs(1:prbs.reglen-1)];
77 ## insert the feedback.
78 for itr2=1:prbs.conlen
79 prbs.sregs(itr2)=nstate(itr2);
80 nstate(itr2)=0; # reset.
87 ## TEST CASES FOR PRBS.
90 ## 2^31 -1 : D31 + D28 + 1 =0 inverted
91 ## 2^23 -1 : D23 + D18 + 1 = 0 ,
92 ## 2^15 -1 : D15 + D14 + 1 = 0,
93 ## 2^10 -1 : D10 + D7 + 1 = 0,
94 ## 2^7 -1 : D7 + D6 + 1 = 0,
95 ## 2^4 -1 : D3 + D2 + 1 = 0,
97 ## +---+ +----+ +---+ +---+
98 ## | D |----| D |---| D |---| D |
99 ## +---+ +----+ +---+ +---+
102 ## [+]---------------+------+
103 ## 1 + 0.D + 1.D^2 + 1.D^3
106 ## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]);
107 ## x = prbs_iterator(prbs,15)
108 ## y = prbs_iterator(prbs,30)(16:end)
109 ## z = prbs_sequence(prbs)
114 ## Multiple Tap, Simple Sequence Generator.
118 ## inits=round(abs(rand(1,n)*1.0))
119 ## prbs=prbs_generator([n 1],{[1 2 k n-1 n]},inits);
120 ## prbs_iterator(prbs,1023)
121 ## prbs_seqlength(prbs,inits)
123 ##prbs=prbs_generator([1 2 3],{[1 2 3]},[1 1 1]);
124 ##prbs_iterator(prbs,7)
127 ## 2^4 -1 : D4 + D1 + 1 = 0,
129 ## +---+ +----+ +---+ +---+
130 ## | D |----| D |---| D |---| D |
131 ## +---+ +----+ +---+ +---+
134 ## [+]---------------+------+
135 ## 1 + 0.D + 1.D^2 + 1.D^3
137 ##prbs=prbs_generator([1 3 4],{[1 2 4]},[1 0 1 1]);
138 ##prbs_iterator(prbs,16)
139 ##prbs_iterator(prbs,32)
142 ##prbs=prbs_generator([7],{[1 7 6]},[1 0 0 1 0 0 0]);
143 ##y=prbs_iterator(prbs,128);
144 ##x=prbs_iterator(prbs,256);