{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By convention, Pxy is computed with the conjugate FFT of X multiplied by the FFT of Y."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the input series differ in length, the shorter series will be zero-padded to match."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "An appropriate amount of overlap will depend on the choice of window and on your requirements. For the default Hann window an overlap of 50% is a reasonable trade-off between accurately estimating the signal power, while not over counting any of the data. Narrower windows may require a larger overlap."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The ratio of the cross spectrum ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scaling='spectrum'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") divided by the cross spectral density ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scaling='density'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") is the constant factor of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "sum(abs(window)**2)*fs / abs(sum(window))**2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". If "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "return_onesided"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the values of the negative frequencies are added to values of the corresponding positive ones."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Consult the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "tutorial_SpectralAnalysis",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section of the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "user_guide",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for a discussion of the scalings of a spectral density and an (amplitude) spectrum."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Welch's method may be interpreted as taking the average over the time slices of a (cross-) spectrogram. Internally, this function utilizes the  "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ShortTimeFFT",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.signal._short_time_fft:ShortTimeFFT"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "  to determine the required (cross-) spectrogram. An example below illustrates that it is straightforward to calculate "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "Pxy",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "Pxy"
              },
              "kind": "local"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " directly with the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ShortTimeFFT",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.signal._short_time_fft:ShortTimeFFT"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". However, there are some notable differences in the behavior of the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ShortTimeFFT",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.signal._short_time_fft:ShortTimeFFT"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "There is no direct "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "ShortTimeFFT",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal._short_time_fft:ShortTimeFFT"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " equivalent for the "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "csd",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal._spectral_py:csd"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " parameter   combination "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "return_onesided=True, scaling='density'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", since   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "fft_mode='onesided2X'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " requires "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'psd'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " scaling. The is due to "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "csd",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal._spectral_py:csd"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "   returning the doubled squared magnitude in this case, which does not have a   sensible interpretation."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "ShortTimeFFT",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal._short_time_fft:ShortTimeFFT"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " uses "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "float64",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " / "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "complex128",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " internally, which is due to the   behavior of the utilized "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "fft",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.fft"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " module. Thus, those are the dtypes being   returned. The "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "csd",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal._spectral_py:csd"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function casts the return values to "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "float32",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " / "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "complex64",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "   if the input is "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "float32",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " / "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "complex64",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " as well."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "csd",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal._spectral_py:csd"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function calculates "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.conj(Sx[q,p]) * Sy[q,p]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", whereas   "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "~ShortTimeFFT.spectrogram",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " calculates "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Sx[q,p] * np.conj(Sy[q,p])"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " where   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Sx[q,p]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Sy[q,p]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are the STFTs of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Also, the window   positioning is different."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 0.16.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": "csd",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.signal._spectral_py:csd"
              },
              "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": "f",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Array of sample frequencies."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "Pxy",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Cross spectral density or cross power spectrum of x,y."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Estimate the cross power spectral density, Pxy, using Welch's method."
            }
          ]
        }
      ],
      "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": "x",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Time series of measurement values"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "y",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Time series of measurement values"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "fs",
              "annotation": "float, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Sampling frequency of the "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " time series. Defaults to 1.0."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "window",
              "annotation": "str or tuple or array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Desired window to use. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "window"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a string or tuple, it is passed to "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "get_window",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal.windows._windows:get_window"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to generate the window values, which are DFT-even by default. See "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "get_window",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.signal.windows._windows:get_window"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for a list of windows and required parameters. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "window"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is array_like it will be used directly as the window and its length must be nperseg. Defaults to a periodic Hann window."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "nperseg",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Length of each segment. Defaults to None, but if window is str or tuple, is set to 256, and if window is array_like, is set to the length of the window."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "noverlap: int, optional",
              "annotation": "",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of points to overlap between segments. If "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "None",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "noverlap = nperseg // 2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Defaults to "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "None",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and may not be greater than "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "nperseg"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "nfft",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Length of the FFT used, if a zero padded FFT is desired. If "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "None",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", the FFT length is "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "nperseg"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Defaults to "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "None",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "detrend",
              "annotation": "str or function or `False`, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Specifies how to detrend each segment. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "detrend"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a string, it is passed as the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "type",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " argument to the "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "detrend"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function. If it is a function, it takes a segment and returns a detrended segment. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "detrend"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "False",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", no detrending is done. Defaults to 'constant'."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "return_onesided",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "True",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", return a one-sided spectrum for real data. If "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "False",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " return a two-sided spectrum. Defaults to "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "True",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", but for complex data, a two-sided spectrum is always returned."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "scaling",
              "annotation": "{ 'density', 'spectrum' }, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Selects between computing the cross spectral density ('density') where "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Pxy",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": null,
                        "version": null,
                        "kind": "local",
                        "path": "Pxy"
                      },
                      "kind": "local"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " has units of V**2/Hz and computing the cross spectrum ('spectrum') where "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Pxy",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": null,
                        "version": null,
                        "kind": "local",
                        "path": "Pxy"
                      },
                      "kind": "local"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " has units of V**2, if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are measured in V and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "fs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is measured in Hz. Defaults to 'density'"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Axis along which the CSD is computed for both inputs; the default is over the last axis (i.e. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "axis=-1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ")."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "average",
              "annotation": "{ 'mean', 'median' }, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Method to use when averaging periodograms. If the spectrum is complex, the average is computed separately for the real and imaginary parts. Defaults to 'mean'."
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionadded",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionadded 1.2.0"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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/_spectral_py.py",
  "item_line": 690,
  "item_type": "function",
  "aliases": [
    "scipy.signal.csd"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "The following example plots the cross power spectral density of two signals with\nsome common features:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy import signal\nimport matplotlib.pyplot as plt\nrng = np.random.default_rng()\n\n# Generate two test signals with some common features:\nN, fs = 100_000, 10e3  # number of samples and sampling frequency\namp, freq = 20, 1234.0  # amplitude and frequency of utilized sine signal\nnoise_power = 0.001 * fs / 2\ntime = np.arange(N) / fs\nb, a = signal.butter(2, 0.25, 'low')\nx = rng.normal(scale=np.sqrt(noise_power), size=time.shape)\ny = signal.lfilter(b, a, x)\nx += amp*np.sin(2*np.pi*freq*time)\ny += rng.normal(scale=0.1*np.sqrt(noise_power), size=time.shape)\n\n# Compute and plot the magnitude of the cross spectral density:\nnperseg, noverlap, win = 1024, 512, 'hann'\nf, Pxy = signal.csd(x, y, fs, win, nperseg, noverlap)\nfig0, ax0 = plt.subplots(tight_layout=True)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.set_title(f\"CSD ({win.title()}-window, {nperseg=}, {noverlap=})\")\nax0.set(xlabel=\"Frequency $f$ in kHz\", ylabel=\"CSD Magnitude in V²/Hz\")\nax0.semilogy(f/1e3, np.abs(Pxy))\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.grid()\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-769169c5ff11c822.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe cross spectral density is calculated by taking the average over the time slices\nof a spectrogram:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "SFT = signal.ShortTimeFFT.from_window('hann', fs, nperseg, noverlap,\n                                      scale_to='psd', fft_mode='onesided2X',\n                                      phase_shift=None)\nSxy1 = SFT.spectrogram(y, x, detr='constant', k_offset=nperseg//2,\n                       p0=0, p1=(N-noverlap) // SFT.hop)\nPxy1 = Sxy1.mean(axis=-1)\nnp.allclose(Pxy, Pxy1)  # same result as with csd()\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAs discussed in the Notes section, the results of using an approach analogous to\nthe code snippet above and the `csd` function may deviate due to implementation\ndetails.\n\nNote that the code snippet above can be easily adapted to determine other\nstatistical properties than the mean value."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "coherence",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.signal._spectral_py:coherence"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Magnitude squared coherence by Welch's method."
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "lombscargle",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.signal._spectral_py:lombscargle"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Lomb-Scargle periodogram for unevenly sampled data"
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "periodogram",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.signal._spectral_py:periodogram"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Simple, optionally modified periodogram"
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "welch",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.signal._spectral_py:welch"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Power spectral density by Welch's method. [Equivalent to csd(x,x)]"
            }
          ]
        }
      ],
      "type": "func"
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "y",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "fs",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "1.0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "window",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "hann_periodic"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "nperseg",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "noverlap",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "nfft",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "detrend",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "constant"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "return_onesided",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "True"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "scaling",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "density"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "-1"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "average",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "mean"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "csd"
  },
  "references": [
    ".. [1] P. Welch, \"The use of the fast Fourier transform for the",
    "       estimation of power spectra: A method based on time averaging",
    "       over short, modified periodograms\", IEEE Trans. Audio",
    "       Electroacoust. vol. 15, pp. 70-73, 1967.",
    ".. [2] Rabiner, Lawrence R., and B. Gold. \"Theory and Application of",
    "       Digital Signal Processing\" Prentice-Hall, pp. 414-419, 1975"
  ],
  "qa": "scipy.signal._spectral_py:csd",
  "arbitrary": [],
  "local_refs": [
    "Pxy",
    "average",
    "axis",
    "detrend",
    "f",
    "fs",
    "nfft",
    "noverlap: int",
    "nperseg",
    "optional",
    "return_onesided",
    "scaling",
    "window",
    "x",
    "y"
  ]
}