In electronics there are standard pseudo-binary sequences. In the literature they talk about the generating polynomials for these sequences:
PRBS-7 : x^7 + x^6 + 1
PRBS-10 : x^11 + x^10 + 1
PRBS-15 : x^15 + x^14 + 1
PRBS-23 : x^23 + x^18 + 1
PRBS-31 : x^31 + x^28 + 1
I was able to find on Wikipedia a snippet of C code for generating PRBS-7 but there was no indication of how to convert this to create the other sequences. What looked like the obvious solution does not work. Would appreciate some help. Here is what I have, but other than for PRBS-7 it generates nothing but zeroes. This code is C# but I would be ok with C or C++ samples.
private static void Generate(int v1, int v2, StringBuilder roots, StringBuilder bits)
{
// This works fine for PRBS7 with v1=7, v2=6 but fails for 15,10; 23,18; 31,28
const byte start = 2;
byte a = start;
for (int i = 1; i < 2000; i++) // I added the 2000 limit, otherwise was infinite loop
{
roots.AppendFormat("{0:X2} ", a);
int newbit = (((a >> v1 - 1) ^ (a >> v2 - 1)) & 1); // my naive attempt to generalize the algorithm
a = (byte)((byte)((a << 1) | newbit) & 0x7f);
bits.Append(newbit);
if (i % 32 == 0)
{
roots.AppendLine();
bits.AppendLine();
}
if (a == start)
{
roots.AppendFormat("\r\nRepetition Period = {0}", i);
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire