A clean and experimental implementation of a Fibonacci LFSR in Python with:
- a basic 4-bit demo (prints 30 iterations exactly as in COM6014 Task 1),
- a general, reconfigurable LFSR class (size/taps/state),
- and an optional helper to compute percentage agreement between a generated stream and a reference sequence.
Conventions (Fibonacci, shift-right)
- State is an
n-bit integer,0 < state < 2^n.- Output bit = LSB (R0) before shifting.
- Feedback bit = XOR parity of the tap positions (0-based;
0 = LSB) in the current state.- New state:
state = (state >> 1) | (feedback << (n - 1)).
- Basic 4-bit LFSR demo:
n=4, taps(3,2), initial state0b0110; printsStateandNextBit(R0)for 30 iterations.
(The first 15 states repeat β period =2^4 β 1 = 15.) - General LFSR class:
- set/get size, state, tap sequence
- next_bit() updates state and returns the next stream bit
- convenience methods: period(), bits(k), get_state_bits()
- Percentage agreement utility (optional): compare a generated bitstream with a reference file.
- Python 3.10+
- No external dependencies
Clone and run:
git clone https://github.com/rmehmood786/Linear-Feedback-Shift-Register.git
cd Linear-Feedback-Shift-Register
# Run the assignment demos (basic + general)
python LFSR.py