§
    fŠtjÄ  ã                   ó  — d Z ddlZddlmZ dgZi ddg“ddg“ddg“d	dg“d
d	g“dd
g“dg d¢“dd	g“ddg“ddg“dg d¢“dg d¢“dg d¢“ddg“dg d¢“ddg“ddg“g d¢dgdgdgdgg d¢d gg d!¢g d"¢d#gd$gg d%¢d&gg d'¢d(œ¥Zd*d)„ZdS )+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                 óæ  — t          j        ¦   «         j        dk    rt           j        nt           j        }|€œ| t
          vrrt          j        t          t
                               ¦   «         ¦  «        ¦  «        }t          d| 
                    ¦   «         › d|                     ¦   «         › d�¦  «        ‚t          j        t
          |          |¦  «        }nŽt          j        t          j        ||¦  «        ¦  «        ddd…         }t          j        |dk     ¦  «        s#t          j        || k    ¦  «        s|j        dk     rt          d	¦  «        ‚t          j        |¦  «        }d
| z  dz
  }|€|}n$t          |¦  «        }|dk     rt          d¦  «        ‚|€"t          j        | t           j        d¬¦  «        }n9t          j        |t$          d¬¦  «                             t           j        ¦  «        }|j        dk    s|j        | k    rt          d¦  «        ‚t          j        |dk    ¦  «        rt          d¦  «        ‚t          j        |t           j        d¬¦  «        }t/          ||| ||¦  «        }||fS )a}
  
    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 Noneéÿÿÿÿr   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           úW/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/signal/_max_len_seq.pyr   r      sF  € õf  œW™YœYÔ/°1Ò4Ð4•”�½"¼(€JØ€|Ø�	Ð!Ð!Ýœ¥$¥y§~¢~Ñ'7Ô'7Ñ"8Ô"8Ñ9Ô9ˆJÝð C°j·n²nÑ6FÔ6Fð Cð CØ *§¢Ñ 0Ô 0ðCð Cð Cñ Dô Dð DåŒx�	 %Ô(¨*Ñ5Ô5ˆˆåŒy�œ $¨
Ñ3Ô3Ñ4Ô4°T°T°r°TÔ:ˆÝŒ6�$˜’(ÑÔð 	;�rœv d¨U¢lÑ3Ô3ð 	;°t´yÀ1²}°}Ýð :ñ ;ô ;ð ;åŒx˜‰~Œ~ˆØ�‰X˜‰N€EØ€~Øˆˆå�V‘”ˆØ�AŠ:ˆ:ÝÐHÑIÔIÐIð €}Ý”˜¥R¤W°CÐ8Ñ8Ô8ˆˆõ ”˜¥d°#Ð6Ñ6Ô6×=Ò=½b¼gÑFÔFˆØ„z�Q‚€˜%œ*¨Ò-Ð-ÝÐBÑCÔCÐCÝ	„vˆe�qŠjÑÔð 8ÝÐ6Ñ7Ô7Ð7å
Œ(�6¥¤°Ð
4Ñ
4Ô
4€CÝ˜t U¨E°6¸3Ñ?Ô?€EØ�ˆ:Ðó    )NNN)Ú__doc__Únumpyr*   r   Ú__all__r/   r   © rJ   rI   ú<module>rO      s‡  ðð Ð à Ð Ð Ð à 2Ð 2Ð 2Ð 2Ð 2Ð 2àˆ/€ð)ˆQ��ð )�Q˜˜ð )˜Q  ð ) Q¨¨ð )¨Q°°ð )°Q¸¸ð )¸QÀ	À	À	ð )Ø��ð)Ø˜!˜ð)Ø  1 #ð)Ø')¨;¨;¨;ð)Ø8:¸K¸K¸Kð)à���ð)à  2 $ð)à(*¨K¨K¨Kð)à9;¸b¸Tð)ð �"�ð)ð (˜<˜<¨b¨T¸°tÀ"ÀØ�˜<˜<˜<¨b¨T°|°|°|Ø�� B 4¨b¨T°{°{°{Ø�˜<˜<˜<ð)ð )ð )€	ðuð uð uð uð uð urJ   