{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The algorithm for MLS generation is generically described in:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "https://en.wikipedia.org/wiki/Maximum_length_sequence"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The default values for taps are specifically taken from the first option listed for each value of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nbits"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "https://web.archive.org/web/20181001062252/http://www.newwaveinstruments.com/resources/articles/m_sequence_linear_feedback_shift_register_lfsr.htm"
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 0.15.0"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Array API Standard Support"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "max_len_seq",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.signal._max_len_seq:max_len_seq"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "SCIPY_ARRAY_API=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "====================  ====================  ====================\nLibrary               CPU                   GPU\n====================  ====================  ====================\nNumPy                 ✅                     n/a                 \nCuPy                  n/a                   ⛔                   \nPyTorch               ⛔                     ⛔                   \nJAX                   ⛔                     ⛔                   \nDask                  ⛔                     n/a                 \n====================  ====================  ====================",
          "execution_status": null
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "See "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "dev-arrayapi",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for more information."
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "seq",
              "annotation": "array",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Resulting MLS sequence of 0's and 1's."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "state",
              "annotation": "array",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The final state of the shift register."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Maximum length sequence (MLS) generator."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "nbits",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of bits to use. Length of the resulting sequence will be "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(2**nbits) - 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Note that generating long sequences (e.g., greater than "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nbits == 16"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ") can take a long time."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "state",
              "annotation": "array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If array, must be of length "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nbits"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", and will be cast to binary (bool) representation. If None, a seed of ones will be used, producing a repeatable representation. If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "state"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is all zeros, an error is raised as this is invalid. Default: None."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "length",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of samples to compute. If None, the entire length "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(2**nbits) - 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is computed."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "taps",
              "annotation": "array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Polynomial taps to use (e.g., "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "[7, 6, 1]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for an 8-bit sequence). If None, taps will be automatically selected (for up to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nbits == 32"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ")."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/signal/_max_len_seq.py",
  "item_line": 22,
  "item_type": "function",
  "aliases": [
    "scipy.signal.max_len_seq"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "MLS uses binary convention:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.signal import max_len_seq\nmax_len_seq(4)[0]\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nMLS has a white spectrum (except for DC):\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom numpy.fft import fft, ifft, fftshift, fftfreq\nseq = max_len_seq(6)[0]*2-1  # +1 and -1\nspec = fft(seq)\nN = len(seq)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.plot(fftshift(fftfreq(N)), fftshift(np.abs(spec)), '.-')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.margins(0.1, 0.1)\nplt.grid(True)\nplt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-21860f5cabce068d.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCircular autocorrelation of MLS is an impulse:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "acorrcirc = ifft(spec * np.conj(spec)).real\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.figure()\nplt.plot(np.arange(-N/2+1, N/2+1), fftshift(acorrcirc), '.-')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.margins(0.1, 0.1)\nplt.grid(True)\nplt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-217c89c1268d43f2.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nLinear autocorrelation of MLS is approximately an impulse:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "acorr = np.correlate(seq, seq, 'full')\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.figure()\nplt.plot(np.arange(-N+1, N), acorr, '.-')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.margins(0.1, 0.1)\nplt.grid(True)\nplt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-933a0e1756011326.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "nbits",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "state",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "length",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "taps",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "max_len_seq"
  },
  "references": null,
  "qa": "scipy.signal._max_len_seq:max_len_seq",
  "arbitrary": [],
  "local_refs": [
    "length",
    "nbits",
    "seq",
    "state",
    "taps"
  ]
}