I'm programming an OFDM system, both the transmitter and receiver sides. The first function where the bits go is the scrambler, which is basically an LFSR, where my polynomial is x^7 + x^4 + 1, simply, I XOR the 7th and 4th bit in the register, and make it the new first bit of the shift register, and also XOR that value with the input value, to get the output value. Pictorially, it can be seen below.
I'm working with a an array of type short to hold the bits. I need this array type due to some later functions in the program. It's more convenient for me. I created a function to shift right the register, and another function for the scrambler. The code can be seen below:
void leftshift(short *in, short *out, unsigned long len, unsigned short shift) {
unsigned long i;
for (i = 0; i < len - shift; i++) {
out[i] = in[i + shift];
}
for (i = len - shift; i < len; i++) {
out[i] = 0;
}
}
void rightshift(short *in, short *out, unsigned long len, unsigned short shift) {
unsigned long i;
for (i = len - 1; i >= shift; i--) {
out[i] = in[i - 1];
}
for (i = 0; i < shift; i++) {
out[i] = 0;
}
}
void scrambler(short *in, short *out, unsigned long len, short *initial_state) {
unsigned long i;
short carry;
short *shift_register = initial_state;
for (i = 0; i < len; i++) {
carry = (shift_register[3] + shift_register[6]) % 2;
rightshift(shift_register, shift_register, 7, 1);
shift_register[0] = carry;
out[i] = (in[i] + carry) % 2;
}
}
Now, the point is that as part of the descrambler process, I need to code the inverse of the scrambler. In my scrambler I'm doing right shift. Does the inverse of it involve just doing a left shift, and leaving the tap sequence and initial configuration of register the same? While, if I do a left shift and check the result, it is not the same result as the initial input. Any ideas?
EDIT:
int main(void) {
const unsigned SIZE = 24;
short in[SIZE] = { 0, 0, 0, 0, 1, 0, 0, 0,
0, 1, 1, 1, 0, 0, 1, 0,
1, 0, 0, 1, 1, 1, 0, 0 };
short init[7] = { 1, 1, 1, 1, 1, 1, 1 };
short *out_scrambler = (short *)malloc(sizeof(short)*SIZE);
short *out_descrambler = (short *)malloc(sizeof(short)*SIZE);
scrambler(in, out_scrambler, SIZE, init);
scrambler(out_scrambler, out_descrambler, SIZE, init);
return 0;
}
