
    (ph                        S r SSKrSSKJr  S/r0 SS/_SS/_SS/_S	S/_S
S	/_SS
/_S/ SQ_SS	/_SS/_SS/_S/ SQ_S/ SQ_S/ SQ_SS/_S/ SQ_SS/_SS/_/ SQS/S/S/S// SQS // S!Q/ S"QS#/S$// S%QS&// S'QS(.ErS*S) jrg)+zTools for MLS generation    N   )_max_len_seq_innermax_len_seq                     )r   r
   r   	   
         )r   r   r      )r   r   r      )r   r   r         )r   r   r         )r   r   r         )      r   r   )         )   r   r   r      )      r   r!   )      r   )r   r   r   r   r   r   r   r   r   r!   r    r#   r"       c                    [         R                  " 5       R                  S:X  a  [         R                  O[         R                  nUc  U [
        ;  a_  [         R                  " [        [
        R                  5       5      5      n[        SUR                  5        SUR                  5        S35      e[         R                  " [
        U    U5      nO[         R                  " [         R                  " X45      5      SSS2   n[         R                  " US:  5      (       d-  [         R                  " X0:  5      (       d  UR                  S:  a  [        S	5      e[         R                  " U5      nS
U -  S-
  nUc  UnO[        U5      nUS:  a  [        S5      eUc%  [         R                   " U [         R"                  SS9nO7[         R                  " U[$        SS9R'                  [         R"                  5      nUR(                  S:w  d  UR                  U :w  a  [        S5      e[         R*                  " US:H  5      (       a  [        S5      e[         R,                  " U[         R"                  SS9n[/        X1XU5      nXq4$ )ay	  
Maximum length sequence (MLS) generator.

Parameters
----------
nbits : int
    Number of bits to use. Length of the resulting sequence will
    be ``(2**nbits) - 1``. Note that generating long sequences
    (e.g., greater than ``nbits == 16``) can take a long time.
state : array_like, optional
    If array, must be of length ``nbits``, and will be cast to binary
    (bool) representation. If None, a seed of ones will be used,
    producing a repeatable representation. If ``state`` is all
    zeros, an error is raised as this is invalid. Default: None.
length : int, optional
    Number of samples to compute. If None, the entire length
    ``(2**nbits) - 1`` is computed.
taps : array_like, optional
    Polynomial taps to use (e.g., ``[7, 6, 1]`` for an 8-bit sequence).
    If None, taps will be automatically selected (for up to
    ``nbits == 32``).

Returns
-------
seq : array
    Resulting MLS sequence of 0's and 1's.
state : array
    The final state of the shift register.

Notes
-----
The algorithm for MLS generation is generically described in:

    https://en.wikipedia.org/wiki/Maximum_length_sequence

The default values for taps are specifically taken from the first
option listed for each value of ``nbits`` in:

    https://web.archive.org/web/20181001062252/http://www.newwaveinstruments.com/resources/articles/m_sequence_linear_feedback_shift_register_lfsr.htm

.. versionadded:: 0.15.0

Examples
--------
MLS uses binary convention:

>>> from scipy.signal import max_len_seq
>>> max_len_seq(4)[0]
array([1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0], dtype=int8)

MLS has a white spectrum (except for DC):

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from numpy.fft import fft, ifft, fftshift, fftfreq
>>> seq = max_len_seq(6)[0]*2-1  # +1 and -1
>>> spec = fft(seq)
>>> N = len(seq)
>>> plt.plot(fftshift(fftfreq(N)), fftshift(np.abs(spec)), '.-')
>>> plt.margins(0.1, 0.1)
>>> plt.grid(True)
>>> plt.show()

Circular autocorrelation of MLS is an impulse:

>>> acorrcirc = ifft(spec * np.conj(spec)).real
>>> plt.figure()
>>> plt.plot(np.arange(-N/2+1, N/2+1), fftshift(acorrcirc), '.-')
>>> plt.margins(0.1, 0.1)
>>> plt.grid(True)
>>> plt.show()

Linear autocorrelation of MLS is approximately an impulse:

>>> acorr = np.correlate(seq, seq, 'full')
>>> plt.figure()
>>> plt.plot(np.arange(-N+1, N), acorr, '.-')
>>> plt.margins(0.1, 0.1)
>>> plt.grid(True)
>>> plt.show()

r   Nznbits must be between z and z if taps is Noner   r   zEtaps must be non-empty with values between zero and nbits (inclusive)r   z)length must be greater than or equal to 0c)dtypeorderz'state must be a 1-D array of size nbitszstate must not be all zeros)npintpitemsizeint32int64	_mls_tapsarraylistkeys
ValueErrorminmaxuniqueanysizeintonesint8boolastypendimallemptyr   )nbitsstatelengthtaps
taps_dtype
known_tapsn_maxseqs           L/var/www/html/venv/lib/python3.13/site-packages/scipy/signal/_max_len_seq.pyr   r      s   f  WWY//14"((J|	!$y~~'7"89J5jnn6F5Gu * 011AC D Dxx	%(*5yy$34TrT:66$(rvvdl33tyy1} : ; ;xx~XNE~VA:HII }RWWC8 d#6==bggFzzQ%**-BCC	vveqj677
((6
4CtE3?E:    )NNN)__doc__numpyr*   r   __all__r/   r    rJ   rI   <module>rO      s     2/)Q )Q )Q )Q )Q )Q )Q	 ))!) 1#)');)8:K)) 2$)(*K)9;bT) ") (bTt"<bT|B4bT{<)	urJ   