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 ## Implement book keeping for a Pseudo-Random Binary Sequence ( PRBS )
17 ## also called as a Linear Feedback Shift Register.
19 ## For the given PRBS in a intial state, compute the PRBS sequence length.
20 ## Length is period of output when the PRBS state is same as
21 ## the start state of PRBS.
23 ## Example: If you had a PRBS shift register like the diagram
24 ## below with 4 registers we use representation by polynomial
25 ## of [ 1 2 3 4], and feedback connections between [ 1 3 4 ].
26 ## The output PRBS sequence is taken from the position 4.
28 ## +---+ +----+ +---+ +---+
29 ## | D |----| D |---| D |---| D |
30 ## +---+ +----+ +---+ +---+
33 ## [+]---------------+------+
34 ## 1 + 0.D + 1.D^2 + 1.D^3
36 ## The code to implement this PRBS will be
37 ## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]);
38 ## x = prbs_sequence(prbs) #gives 15
41 ## See Also: This function is to be used along with functions
44 function [itrs,seq]=prbs_sequence(prbs)
48 nstate=zeros(1,prbs.reglen);
52 ## For each iteration, shift the output bit. Then compute the xor pattern of connections.
53 ## Finally apply feedback the stuff. Insert the computed pattern.
57 ## compute the feedback.
58 for itr2=1:prbs.conlen
60 L=length(prbs.connections{itr2});
62 val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3)));
64 nstate(prbs.connections{itr2}(1))=val;
67 ## rotate the output discarding the last output.
68 seq = [seq, prbs.sregs(end)];
69 prbs.sregs=[0 prbs.sregs(1:prbs.reglen-1)];
71 ## insert the feedback.
72 for itr2=1:prbs.conlen
73 prbs.sregs(itr2)=nstate(itr2);
74 nstate(itr2)=0; # reset.
77 if(isequal(prbs.sregs,inits))