Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PRBS.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_math
3/// \notebook -nodraw
4/// Tutorial illustrating the use of ROOT::Math::LFSR::GenerateSequence
5/// can be run with:
6///
7/// ~~~{.cpp}
8/// root > .x PRBS.C
9/// root > .x PRBS.C+ with ACLIC
10/// ~~~
11///
12/// These values match the PRBS sequences generated by a Keysight waveform generator
13/// except for the N first bits that appear at the end rather than at the beginning
14/// \see https://www.sciencedirect.com/science/article/pii/S0168900222002431#fig6
15///
16/// \macro_output
17/// \macro_code
18///
19/// \author Fernando Hueso-González
20
21#include <Math/LFSR.h>
22#include <iostream>
23
24void PRBS()
25{
26 printf("\nLFSR::GenerateSequence PRBS3, PRBS4 and PRBS5 tests\n");
27 printf("==========================\n");
28
29 // PRBS3
30 std::array<std::uint16_t, 2> taps3 = {3, 2}; // Exponents of the monic polynomial
31 auto prbs3 = ROOT::Math::LFSR::GenerateSequence(std::bitset<3>().flip(), taps3); // Start value all high
32
33 // PRBS4
34 std::array<std::uint16_t, 2> taps4 = {4, 3}; // Exponents of the monic polynomial
35 auto prbs4 = ROOT::Math::LFSR::GenerateSequence(std::bitset<4>().flip(), taps4); // Start value all high
36
37 // PRBS5
38 std::array<std::uint16_t, 2> taps5 = {5, 3}; // Exponents of the monic polynomial
39 auto prbs5 = ROOT::Math::LFSR::GenerateSequence(std::bitset<5>().flip(), taps5); // Start value all high
40
41 for (auto prbs : {prbs3, prbs4, prbs5}) {
42 std::cout << "PRBS period " << prbs.size() << ":\t";
43 for (auto p : prbs) {
44 std::cout << static_cast<unsigned short>(p) << " ";
45 }
46 std::cout << std::endl;
47 }
48
49 // Find below all exponents of the monic polynomial extracted from
50 // Keysight Trueform Series Operating and Service Guide p. 284-285
51 // clang-format off
52 // auto prbs3 = ROOT::Math::LFSR::GenerateSequence< 3, 2, bool>(bitset<3 >().flip(), std::array<std::uint16_t, 2>{3, 2});
53 // auto prbs4 = ROOT::Math::LFSR::GenerateSequence< 4, 2, bool>(bitset<4 >().flip(), std::array<std::uint16_t, 2>{4, 3});
54 // auto prbs5 = ROOT::Math::LFSR::GenerateSequence< 5, 2, bool>(bitset<5 >().flip(), std::array<std::uint16_t, 2>{5, 3});
55 // auto prbs6 = ROOT::Math::LFSR::GenerateSequence< 6, 2, bool>(bitset<6 >().flip(), std::array<std::uint16_t, 2>{6, 5});
56 // auto prbs7 = ROOT::Math::LFSR::GenerateSequence< 7, 2, bool>(bitset<7 >().flip(), std::array<std::uint16_t, 2>{7, 6});
57 // auto prbs8 = ROOT::Math::LFSR::GenerateSequence< 8, 4, bool>(bitset<8 >().flip(), std::array<std::uint16_t, 4>{8, 6, 5, 4});
58 // auto prbs9 = ROOT::Math::LFSR::GenerateSequence< 9, 2, bool>(bitset<9 >().flip(), std::array<std::uint16_t, 2>{9, 5});
59 // auto prbs10 = ROOT::Math::LFSR::GenerateSequence<10, 2, bool>(bitset<10>().flip(), std::array<std::uint16_t, 2>{10, 7});
60 // auto prbs11 = ROOT::Math::LFSR::GenerateSequence<11, 2, bool>(bitset<11>().flip(), std::array<std::uint16_t, 2>{11, 9});
61 // auto prbs12 = ROOT::Math::LFSR::GenerateSequence<12, 4, bool>(bitset<12>().flip(), std::array<std::uint16_t, 4>{12, 6, 4, 1});
62 // auto prbs13 = ROOT::Math::LFSR::GenerateSequence<13, 4, bool>(bitset<13>().flip(), std::array<std::uint16_t, 4>{13, 4, 3, 1});
63 // auto prbs14 = ROOT::Math::LFSR::GenerateSequence<14, 4, bool>(bitset<14>().flip(), std::array<std::uint16_t, 4>{14, 5, 3, 1});
64 // auto prbs15 = ROOT::Math::LFSR::GenerateSequence<15, 2, bool>(bitset<15>().flip(), std::array<std::uint16_t, 2>{15, 14});
65 // auto prbs16 = ROOT::Math::LFSR::GenerateSequence<16, 4, bool>(bitset<16>().flip(), std::array<std::uint16_t, 4>{16, 15, 13, 4});
66 // auto prbs17 = ROOT::Math::LFSR::GenerateSequence<17, 2, bool>(bitset<17>().flip(), std::array<std::uint16_t, 2>{17, 14});
67 // auto prbs18 = ROOT::Math::LFSR::GenerateSequence<18, 2, bool>(bitset<18>().flip(), std::array<std::uint16_t, 2>{18, 11});
68 // auto prbs19 = ROOT::Math::LFSR::GenerateSequence<19, 4, bool>(bitset<19>().flip(), std::array<std::uint16_t, 4>{19, 6, 2, 1});
69 // auto prbs20 = ROOT::Math::LFSR::GenerateSequence<20, 2, bool>(bitset<20>().flip(), std::array<std::uint16_t, 2>{20, 17});
70 // auto prbs21 = ROOT::Math::LFSR::GenerateSequence<21, 2, bool>(bitset<21>().flip(), std::array<std::uint16_t, 2>{21, 19});
71 // auto prbs22 = ROOT::Math::LFSR::GenerateSequence<22, 2, bool>(bitset<22>().flip(), std::array<std::uint16_t, 2>{22, 21});
72 // auto prbs23 = ROOT::Math::LFSR::GenerateSequence<23, 2, bool>(bitset<23>().flip(), std::array<std::uint16_t, 2>{23, 18});
73 // auto prbs24 = ROOT::Math::LFSR::GenerateSequence<24, 4, bool>(bitset<24>().flip(), std::array<std::uint16_t, 4>{24, 23, 22, 17}, true); // Turn allow wrapping to save memory
74 // auto prbs25 = ROOT::Math::LFSR::GenerateSequence<25, 2, bool>(bitset<25>().flip(), std::array<std::uint16_t, 2>{25, 22}, true); // Turn allow wrapping to save memory
75 // auto prbs26 = ROOT::Math::LFSR::GenerateSequence<26, 4, bool>(bitset<26>().flip(), std::array<std::uint16_t, 4>{26, 6, 2, 1}, true); // Turn allow wrapping to save memory
76 // auto prbs27 = ROOT::Math::LFSR::GenerateSequence<27, 4, bool>(bitset<27>().flip(), std::array<std::uint16_t, 4>{27, 5, 2, 1}, true); // Turn allow wrapping to save memory
77 // auto prbs28 = ROOT::Math::LFSR::GenerateSequence<28, 2, bool>(bitset<28>().flip(), std::array<std::uint16_t, 2>{28, 25}, true); // Turn allow wrapping to save memory
78 // auto prbs29 = ROOT::Math::LFSR::GenerateSequence<29, 4, bool>(bitset<29>().flip(), std::array<std::uint16_t, 4>{29, 27}, true); // Turn allow wrapping to save memory
79 // auto prbs30 = ROOT::Math::LFSR::GenerateSequence<30, 4, bool>(bitset<30>().flip(), std::array<std::uint16_t, 4>{30, 6, 4, 1}, true); // Turn allow wrapping to save memory
80 // auto prbs31 = ROOT::Math::LFSR::GenerateSequence<31, 2, bool>(bitset<31>().flip(), std::array<std::uint16_t, 2>{31, 28}, true); // Turn allow wrapping to save memory
81 // auto prbs32 = ROOT::Math::LFSR::GenerateSequence<32, 4, bool>(bitset<32>().flip(), std::array<std::uint16_t, 4>{32, 22, 2, 1}, true); // Turn allow wrapping to save memory
82 // clang-format on
83}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
std::vector< Output > GenerateSequence(std::bitset< k > start, std::array< std::uint16_t, nTaps > taps, bool left=true, bool wrapping=false, bool oppositeBit=false)
Generation of a sequence of pseudo-random bits using a linear feedback shift register (LFSR),...
Definition LFSR.h:107