Can you be more specific about where you are having a problem? Coding examples for LFSR PN sequences has been documented for many years. The coding example you posted seems overly complicated to me. Perhaps you can start with a simpler example and see if you can build up from that?