/* ECE420, Lab 4, Reference PN Generator Implementation (Non-Optimized) */ /* Matt Kleffner 08/04 */ /* Original by Michael Frutiger 02/24/04 */ /* Use governed by the Creative Commons Attribution License */ #include "lab4b.h" extern unsigned int *iseed; extern int autocorr_in[N]; /* Returns as an integer a random bit, based on the 15 lowest significant bits in iseed (which is modified for the next call). */ int randbit() { int newbit; /* XOR bits 15, 1 and 0 of iseed */ newbit = (*iseed >> 15) & 1 ^ (*iseed >> 1) & 1 ^ *iseed & 1; /* Leftshift the seed and put the result of the XOR's in bit 1. */ *iseed=(*iseed << 1) | newbit; return(newbit); } void rand_fillbuffer(void) { int i; for (i = 0; i < N; ++i) { if (randbit()) autocorr_in[i] = 32767; else autocorr_in[i] = -32767; } }