Ayup - the subject says it all. Just trying not to reinvent the wheel. Thanks in advance. Since most people here don't like us posting code to the group, please email me at randy.yates@sonyericsson.com. Mucho Gracias! --Randy
Seeking C or C++ Code for MLS Sequence Generation
Started by ●October 30, 2003
Reply by ●October 30, 20032003-10-30
Just out of curiosity, why don't people like others posting code? Is it a bandwidth thing? A MLS sequence can't be more than a hand-full of lines of code. Probably less characters than the original question. "Randy Yates" <yates@ieee.org> wrote in message news:567ce618.0310301506.4da41825@posting.google.com...> Ayup - the subject says it all. Just trying not to reinvent > the wheel. Thanks in advance. > > Since most people here don't like us posting code to the group, > please email me at randy.yates@sonyericsson.com. > > Mucho Gracias! > > --Randy
Reply by ●October 30, 20032003-10-30
Randy Yates wrote:> Ayup - the subject says it all. Just trying not to reinvent > the wheel. Thanks in advance.Two minutes on Google makes me think MLS is similar to a Linear Feedback Shift-Register (LFSR), which some people also call PN generators.> Since most people here don't like us posting code to the group, > please email me at randy.yates@sonyericsson.com.Says who? An LFSR routine is less than a dozen lines, however, we would need to know how many bits long your sequence needs to be.> Mucho Gracias! > > --Randy-- Phil Frisbie, Jr. Hawk Software http://www.hawksoft.com
Reply by ●October 30, 20032003-10-30
Hello Randy, Because of the simlarity between PN and MLS sequences, try looking at chapter 7 of numerical recipes. I think the section on random bits is the right area. The book is online at the following link: http://lib-www.lanl.gov/numerical/bookcpdf.html Clay "Randy Yates" <yates@ieee.org> wrote in message news:567ce618.0310301506.4da41825@posting.google.com...> Ayup - the subject says it all. Just trying not to reinvent > the wheel. Thanks in advance. > > Since most people here don't like us posting code to the group, > please email me at randy.yates@sonyericsson.com. > > Mucho Gracias! > > --Randy
Reply by ●October 31, 20032003-10-31
physics@bellsouth.net wrote:> Hello Randy, > Because of the simlarity between PN and MLS sequences, try looking at > chapter 7 of numerical recipes. I think the section on random bits is the > right area. The book is online at the following link: > > http://lib-www.lanl.gov/numerical/bookcpdf.html > > > ClayOnce again I thank you, Clay. -- % Randy Yates % "...the answer lies within your soul %% Fuquay-Varina, NC % 'cause no one knows which side %%% 919-577-9882 % the coin will fall." %%%% <yates@ieee.org> % 'Big Wheels', *Out of the Blue*, ELO http://home.earthlink.net/~yatescr
Reply by ●October 31, 20032003-10-31
Try this...
#include <iostream.h>
#include <math.h>
#define SCALE 0
int make_mls(long* mls, long* p1, long* p2, int degree)
{
int taps[10];
int ntaps;
ntaps = set_taps(taps,degree);
gen_mls(mls,p1,p2,taps,degree,ntaps);
return 0;
}
int fht(double* measured, long* p1, long* p2, double* impulse, int degree)
{
register kd, k, j, i;
long stages, points, p, dist;
long nr;
double temp;
nr = (long)(pow(2,degree)-1);
points = nr + 1;
p = points;
stages = 1;
while(p>2)
{
p = p>>1;
stages = stages + 1;
}
for(i=0;i<stages;i++)
{
dist = 1<<i;
for(j=0;j<dist;j++)
{
k = j;
while(k<points)
{
kd = k + dist;
temp = *(measured+(*(p1+k))); // fast way of computing temp = measured[
p1[k] ]
*(measured+(*(p1+k))) = temp +*(measured+(*(p1+kd)));
*(measured+(*(p1+kd))) = temp -*(measured+(*(p1+kd)));
k = k + 2 * dist;
}
}
}
for(i=0;i<nr;i++)
{
impulse[i] = measured[p1[p2[i+1]]] / nr;
}
return 0;
}
int set_taps(int* taps, int degree) /// Generate mls taps ///
{
int ntaps;
if ( (degree<5)||(degree==6)||(degree==15) )
{
ntaps = 2;
taps[0] = 0;
taps[1] = 1;
}
else if (degree == 7)
{
ntaps = 2;
taps[0] = 0;
taps[1] = 1;
}
else if (degree==5||degree==11)
{
ntaps = 2;
taps[0] = 0;
taps[1] = 2;
}
else if (degree==8)
{
ntaps = 4;
taps[0] = 0;
taps[1] = 1;
taps[2] = 5;
taps[3] = 6;
}
else if (degree==9)
{
ntaps = 2;
taps[0] = 0;
taps[1] = 4;
}
else if (degree==10)
{
ntaps = 2;
taps[0] = 0;
taps[1] = 3;
}
else if (degree==12)
{
ntaps = 4;
taps[0] = 0;
taps[1] = 3;
taps[2] = 4;
taps[3] = 7;
}
else if (degree==13)
{
ntaps = 4;
taps[0] = 0;
taps[1] = 1;
taps[2] = 3;
taps[3] = 4;
}
else if (degree==14)
{
ntaps = 4;
taps[0] = 0;
taps[1] = 1;
taps[2] = 11;
taps[3] = 12;
}
else if (degree==16)
{
ntaps = 4;
taps[0] = 0;
taps[1] = 2;
taps[2] = 3;
taps[3] = 5;
}
return ntaps;
}
int make_p2(long* mls, long* p1, long* p2, long nr)
{
register a;
long row_tag, col, n, temp;
p2[0] = 0;
for(a=0;a<nr;a++)
{
col = 1;
temp = 0;
while(col<nr)
{
n = p1[col] - a;
if(n<0)
{
n = n + nr;
}
row_tag = (long)((1 - mls[n]) / 2) * col;
temp = temp + row_tag;
col = col<<1;
}
p2[a+1] = temp;
}
return 0;
}
int gen_mls(long* mls, long* p1, long* p2, int* taps, int degree, int ntaps)
{
register i,j;
long nr;
long shift_reg, temp_reg, lsb;
double A,C;
nr = (long)(pow(2,degree)-1);
if(SCALE)
{
A = 1/sqrt(nr+1);
C = (-1+sqrt(nr+1))/nr;
}
else
{
A = 1;
C = 0;
}
shift_reg = 1;
p1[0] = nr;
for(i=0;i<nr;i++)
{
lsb = shift_reg&1;
mls[i] = 1 - (2 * lsb);
if(i<= (nr-degree))
{
p1[shift_reg] = i + degree - 1;
}
else
{
p1[shift_reg] = i + degree - nr - 1;
}
for(j=1;j<ntaps;j++)
{
temp_reg = shift_reg;
lsb = lsb^((temp_reg>>(degree-taps[j]))&1);
}
shift_reg = shift_reg>>1;
shift_reg = shift_reg + (lsb<<(degree-1));
}
make_p2(mls,p1,p2,nr);
return 1;
}
Hope that helps =:-)
Dr Andrew Rimell
Human Sciences Department
Loughborough University
Loughborough
LE11 3TU
UK
Tel: 01509 228816
Fax: 01509 223940
Reply by ●November 1, 20032003-11-01
Thomas Magma wrote:> Just out of curiosity, why don't people like others posting code? Is it a > bandwidth thing?Yes.> A MLS sequence can't be more than a hand-full of lines of > code. Probably less characters than the original question.Then it probably doesn't matter. -- % Randy Yates % "...the answer lies within your soul %% Fuquay-Varina, NC % 'cause no one knows which side %%% 919-577-9882 % the coin will fall." %%%% <yates@ieee.org> % 'Big Wheels', *Out of the Blue*, ELO http://home.earthlink.net/~yatescr
Reply by ●November 1, 20032003-11-01
"Randy Yates" <yates@ieee.org> wrote in message news:567ce618.0310301506.4da41825@posting.google.com...> Ayup - the subject says it all. Just trying not to reinvent > the wheel. Thanks in advance.#define POLY ((unsigned long)0x82608EDB) unsigned long state=1; for(;;) { if (state&1) {write(1);state=(state>>1)^POLY;} else {write(-1);state=(state>>1);} } That's it. I hereby place it in the public domain. POLY is a bit mask representing a primitive polynomial over GF(2), with the lowest 1 shifted out. If the most significant 1 bit in poly is 2^N, the length of the sequence is 2^(N+1)-1. The position of the most significant 1 bit determines the The choise of POLY determines the order and some other qualities of the sequence. The #define above is my default choice -- the polynomial used for the CRC-32 checksum in Ethernet and many other places.
Reply by ●November 2, 20032003-11-02
Reply by ●November 2, 20032003-11-02
Hey - thanks Matt! --Randy Matt Timmermans wrote:> "Randy Yates" <yates@ieee.org> wrote in message > news:567ce618.0310301506.4da41825@posting.google.com... > >>Ayup - the subject says it all. Just trying not to reinvent >>the wheel. Thanks in advance. > > > #define POLY ((unsigned long)0x82608EDB) > unsigned long state=1; > for(;;) > { > if (state&1) > {write(1);state=(state>>1)^POLY;} > else > {write(-1);state=(state>>1);} > } > > That's it. I hereby place it in the public domain. POLY is a bit mask > representing a primitive polynomial over GF(2), with the lowest 1 shifted > out. If the most significant 1 bit in poly is 2^N, the length of the > sequence is 2^(N+1)-1. The position of the most significant 1 bit > determines the The choise of POLY determines the order and some other > qualities of the sequence. The #define above is my default choice -- the > polynomial used for the CRC-32 checksum in Ethernet and many other places. > > >-- % Randy Yates % "...the answer lies within your soul %% Fuquay-Varina, NC % 'cause no one knows which side %%% 919-577-9882 % the coin will fall." %%%% <yates@ieee.org> % 'Big Wheels', *Out of the Blue*, ELO http://home.earthlink.net/~yatescr






