]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/prbs_generator.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / prbs_generator.m
1 ## Copyright (C) 2006 Muthiah Annamalai <muthiah.annamalai@uta.edu>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## Implement book keeping for a Pseudo-Random Binary Sequence ( PRBS )
17 ## also called as a Linear Feedback Shift Register.
18 ## 
19 ## Given a polynomial create a PRBS structure for that polynomial.
20 ## Now all we need is to just create this polynomial and make it work.
21 ## polynomial must be a vector containing the powers of x and an optional
22 ## value 1. eg: x^3 + x^2 + x + 1 must be written as [3 2 1 0]
23 ## all the coefficients are either 1 or 0. It generates only a Binary \
24 ## sequence, and the generator polynomial need to be only a binary
25 ## polynomial in GF(2).
26 ## 
27 ## connections, contains a struct of vectors where each vector is the
28 ## connection list mapping its vec(2:end) elements to the vec(1) output.
29 ## 
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.
34 ## 
35 ##  +---+    +----+   +---+   +---+
36 ##  | D |----| D  |---| D |---| D |
37 ##  +---+    +----+   +---+   +---+
38 ##    |                 |       |
39 ##    \                 /      /
40 ##    [+]---------------+------+
41 ##   1   +    0.D   + 1.D^2 + 1.D^3
42 ## 
43 ## The code to implement this PRBS with a start state of [1 0 1 1]
44 ## will be:
45 ## 
46 ## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]);
47 ## x = prbs_sequence(prbs) #gives 15
48 ## 
49 ## prbs_iterator( prbs, 15 ) #15 binary digits seen
50 ## [ 1   1   0   1   0   1   1   1   1   0   0   0   1   0   0 ]
51 ## 
52 ## See Also: This function is to be used along with functions 
53 ## prbs_iterator, and prbs_sequence.
54
55 function prbs=prbs_generator(polynomial,connections,initstate)
56   prbs.reglen=max(polynomial);
57   prbs.polynomial=polynomial;
58   prbs.sregs=initstate;
59   prbs.connections=connections;
60   prbs.conlen=length(connections);
61 end