[SciPy-Dev] Maximum length sequence
Neal Becker
ndbecker2 at gmail.com
Fri Feb 21 16:27:52 EST 2014
Robert Kern wrote:
> On Wed, Feb 19, 2014 at 1:37 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
>> Eric Larson wrote:
>>
>>> Maximum length sequences (MLS) are useful in signal processing for finding
>>> impulse responses. I can't find a great implementation of MLS in Python,
>>> but maybe I've missed one somewhere. Would this be something good to put in
>>> scipy.signal, perhaps as scipy.signal.mls?
>>>
>>> Cheers,
>>> Eric
>>
>> If you want a sequence of gaussian rv, just use numpy.random.
>
> That does not appear to be what he wants:
>
> http://en.wikipedia.org/wiki/Maximum_length_sequence
>
I'm assuming what's wanted here is white noise.
To generate random bits of some specified bit width, I use the underlying
mersenne twister to generate uniform integer r.v., then cache the bits (32 at a
time) and output them with the desired width.
Of course this is not identical to what the OP asked, but serves the same
purpose.
A snippet of the C++ code used for this looks like:
template<class Engine>
result_type operator() (Engine& eng) {
if (count <= width-1) {
cache = eng();
count = std::min (std::numeric_limits<typename
Engine::result_type>::digits, std::numeric_limits<result_type>::digits);
}
result_type bits = cache & mask;
cache >>= width;
count -= width;
return bits;
}
More information about the SciPy-Dev
mailing list