From 032d359a90d51ade7c3311bc1960aaf3b645f3a3 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 3 Jul 2015 12:36:27 -0400 Subject: [PATCH] cmMath.h/c : Added cmLFSR() and cmGenGoldCode(). --- cmMath.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- cmMath.h | 37 ++++++++++++++++ 2 files changed, 166 insertions(+), 2 deletions(-) diff --git a/cmMath.c b/cmMath.c index 028354e..f740b1b 100644 --- a/cmMath.c +++ b/cmMath.c @@ -1,5 +1,10 @@ #include "cmPrefix.h" #include "cmGlobal.h" +#include "cmRpt.h" +#include "cmErr.h" +#include "cmCtx.h" +#include "cmMem.h" +#include "cmMallocDebug.h" #include "cmFloatTypes.h" #include "cmMath.h" #include // u_char @@ -464,6 +469,128 @@ bool cmIsCloseU( unsigned x0, unsigned x1, double eps ) { if( x0 == x1 ) return true; - - return abs(x0-x1)/(x0+x1) < eps; + if( x0 > x1 ) + return (x0-x1)/(x0+x1) < eps; + else + return (x1-x0)/(x0+x1) < eps; +} + +//================================================================= + +// cmLFSR() implementation based on note at bottom of: +// http://www.ece.cmu.edu/~koopman/lfsr/index.html +void cmLFSR( unsigned lfsrN, unsigned tapMask, unsigned seed, unsigned* yV, unsigned yN ) +{ + assert( 0 < lfsrN && lfsrN < 32 ); + + unsigned i; + for(i=0; i> 1) ^ tapMask; + else + seed = (seed >> 1); + + } +} + +bool cmMLS_IsBalanced( const unsigned* xV, int xN) +{ + int a = 0; + unsigned i; + + for(i=0; ilfsrN) - 1. +// Note that values of 'lfsrN' and the 'poly_coeffx' must be carefully selected such that +// they will produce a MLS. For example to generate a MLS with length 31 set 'lfsrN' to 5 and +// then select poly_coeff from two different elements of the set {0x12 0x14 0x17 0x1B 0x1D 0x1E}. +// See http://www.ece.cmu.edu/~koopman/lfsr/index.html for a complete set of MSL polynomial +// coefficients for given LFSR lengths. +// Returns false if insufficient balanced pairs exist. +bool cmGenGoldCodes( unsigned lfsrN, unsigned poly_coeff0, unsigned poly_coeff1, unsigned goldN, int* yM, unsigned mlsN ); + #endif