Search code examples
matlabsequencepseudocode

Generate pseudo code with commsrc.pn


I create my PN generator with this code:

h=commsrc.pn('GenPoly',gfprimdf(3), 'InitialStates',[1 0 0], ...
             'CurrentStates', [1 0 0], 'Mask',[0 0 1], 'NumBitsOut',1)

And this is the GF polynomial of my PN generator:

>> gfpretty(h.GenPoly)
                                         3
                                1 + X + X 

The current states of h is:

>> h.CurrentStates
   ans =
             1     0     0

looking at the GF polynomial, I think the next statue of h should be [0 1 0]. But Matlab turns the next states of h into [1 1 0] not the expected value [0 1 0].

>> generate(h);
>> h.CurrentStates
 ans =
            1     1     0

Solution

  • gfprimdf(...) generates the generator polynomial in the order 1+a1*x+a2*x^2+a3*x^3+...+x^N and represents this as a vector

    [1 a_1 a_2 ... a_N-1 1]

    (ascending order of polynomial powers). However, commsrc.pn expects this vector to be in descending order.

    Thus, in your example, the generator polynomial which is really used by commsrc.pn is 1+x^2+x^3, and not 1+x+x^3 as intended. If you instead use

    h=commsrc.pn('GenPoly',[1 0 1 1],'InitialStates',[1 0 0],'CurrentStates',[1 0 0],'Mask',[0 0 1],'NumBitsOut',1);

    the state after generating one output bit results in the expected state.