{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Any complex-valued signal "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be described by a real-valued instantaneous amplitude "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "a(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and a real-valued instantaneous phase "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\phi(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", i.e., "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z(t) = a(t) \\exp\\!\\big(j \\phi(t)\\big)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The envelope is defined as the absolute value of the amplitude "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "|a(t)| = |z(t)|"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which is at the same time the absolute value of the signal. Hence, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "|a(t)|"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " \"envelopes\" the class of all signals with amplitude "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "a(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and arbitrary phase "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\phi(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For real-valued signals, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x(t) = a(t) \\cos\\!\\big(\\phi(t)\\big)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the analogous formulation. Hence, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "|a(t)|"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be determined by converting "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " into an analytic signal "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z_a(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " by means of a Hilbert transform, i.e., "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z_a(t) = a(t) \\cos\\!\\big(\\phi(t)\\big) + j a(t) \\sin\\!\\big(\\phi(t) \\big)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which produces a complex-valued signal with the same envelope "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "|a(t)|"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The implementation is based on computing the FFT of the input signal and then performing the necessary operations in Fourier space. Hence, the typical FFT caveats need to be taken into account:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The signal is assumed to be periodic. Discontinuities between signal start and   end can lead to unwanted results due to Gibbs phenomenon."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The FFT is slow if the signal length is prime or very long. Also, the memory   demands are typically higher than a comparable FIR/IIR filter based   implementation."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The frequency spacing "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1 / (n*T)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for corner frequencies of the bandpass filter   corresponds to the frequencies produced by "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "scipy.fft.fftfreq(len(z), T)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the envelope of a complex-valued signal "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "z"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with no bandpass filtering is desired, i.e., "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "bp_in=(None, None)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", then the envelope corresponds to the absolute value. Hence, it is more efficient to use "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "np.abs(z)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " instead of this function."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Although computing the envelope based on the analytic signal "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the natural method for real-valued signals, other methods are also frequently used. The most popular alternative is probably the so-called \"square-law\" envelope detector and its relatives "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". They do not always compute the correct result for all kinds of signals, but are usually correct and typically computationally more efficient for most kinds of narrowband signals. The definition for an envelope presented here is common where instantaneous amplitude and phase are of interest (e.g., as described in "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "). There exist also other concepts, which rely on the general mathematical idea of an envelope "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "4"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ": A pragmatic approach is to determine all upper and lower signal peaks and use a spline interpolation to determine the curves "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__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": "envelope",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.signal._signaltools:envelope"
              },
              "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": "",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If parameter "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "residual"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " then an array "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "z_env"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with the same shape as the input "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "z"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is returned, containing its envelope. Otherwise, an array with shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(2, *z.shape)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", containing the arrays "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "z_env"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "z_res"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", stacked along the first axis, is returned. It allows unpacking, i.e., "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "z_env, z_res = envelope(z, residual='all')"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". The residual "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "z_res"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " contains the signal part which the input bandpass filter removed, depending on the parameter "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "residual"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Note that for real-valued signals, a real-valued residual is returned. Hence, the negative frequency components of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "bp_in"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are ignored."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute the envelope of a real- or complex-valued signal."
            }
          ]
        }
      ],
      "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": "z",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Real- or complex-valued input signal, which is assumed to be made up of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " samples and having sampling interval "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "T"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "z"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " may also be a multidimensional array with the time axis being defined by "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "bp_in",
              "annotation": "tuple[int | None, int | None], optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "2-tuple defining the frequency band "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "bp_in[0]:bp_in[1]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of the input filter. The corner frequencies are specified as integer multiples of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1/(n*T)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "-n//2 <= bp_in[0] < bp_in[1] <= (n+1)//2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " being the allowed frequency range. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " entries are replaced with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "-n//2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(n+1)//2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " respectively. The default of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(1, None)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " removes the mean value as well as the negative frequency components."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "n_out",
              "annotation": "int | None, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If not "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " the output will be resampled to "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "n_out"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " samples. The default of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " sets the output to the same length as the input "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "z"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "squared",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If set, the square of the envelope is returned. The bandwidth of the squared envelope is often smaller than the non-squared envelope bandwidth due to the nonlinear nature of the utilized absolute value function. I.e., the embedded square root function typically produces addiational harmonics. The default is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "False"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "residual",
              "annotation": "Literal['lowpass', 'all', None], optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "This option determines what kind of residual, i.e., the signal part which the input bandpass filter removes, is returned. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'all'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " returns everything except the contents of the frequency band "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "bp_in[0]:bp_in[1]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'lowpass'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " returns the contents of the frequency band "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "< bp_in[0]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " then only the envelope is returned. Default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'lowpass'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Axis of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "z"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " over which to compute the envelope. Default is last the axis."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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/_signaltools.py",
  "item_line": 2715,
  "item_type": "function",
  "aliases": [
    "scipy.signal.envelope"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "The following plot illustrates the envelope of a signal with variable frequency and\na low-frequency drift. To separate the drift from the envelope, a 4 Hz highpass\nfilter is used. The low-pass residuum of the input bandpass filter is utilized to\ndetermine an asymmetric upper and lower bound to enclose the signal. Due to the\nsmoothness of the resulting envelope, it is down-sampled from 500 to 40 samples.\nNote that the instantaneous amplitude ``a_x`` and the computed envelope ``x_env``\nare not perfectly identical. This is due to the signal not being perfectly periodic\nas well as the existence of some spectral overlapping of ``x_carrier`` and\n``x_drift``. Hence, they cannot be completely separated by a bandpass filter.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.signal.windows import gaussian\nfrom scipy.signal import envelope\nn, n_out = 500, 40  # number of signal samples and envelope samples\nT = 2 / n  # sampling interval for 2 s duration\nt = np.arange(n) * T  # time stamps\na_x = gaussian(len(t), 0.4/T)  # instantaneous amplitude\nphi_x = 30*np.pi*t + 35*np.cos(2*np.pi*0.25*t)  # instantaneous phase\nx_carrier = a_x * np.cos(phi_x)\nx_drift = 0.3 * gaussian(len(t), 0.4/T)  # drift\nx = x_carrier + x_drift\nbp_in = (int(4 * (n*T)), None)  # 4 Hz highpass input filter\nx_env, x_res = envelope(x, bp_in, n_out=n_out)\nt_out = np.arange(n_out) * (n / n_out) * T\nfg0, ax0 = plt.subplots(1, 1, tight_layout=True)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.set_title(r\"$4\\,$Hz Highpass Envelope of Drifting Signal\")\nax0.set(xlabel=\"Time in seconds\", xlim=(0, n*T), ylabel=\"Amplitude\")\nax0.plot(t, x, 'C0-', alpha=0.5, label=\"Signal\")\nax0.plot(t, x_drift, 'C2--', alpha=0.25, label=\"Drift\")\nax0.plot(t_out, x_res+x_env, 'C1.-', alpha=0.5, label=\"Envelope\")\nax0.plot(t_out, x_res-x_env, 'C1.-', alpha=0.5, label=None)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.grid(True)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.legend()\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-0a4cdd0a1a7b5b56.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe second example provides a geometric envelope interpretation of complex-valued\nsignals: The following two plots show the complex-valued signal as a blue\n3d-trajectory and the envelope as an orange round tube with varying diameter, i.e.,\nas :math:`|a(t)| \\exp(j\\rho(t))`, with :math:`\\rho(t)\\in[-\\pi,\\pi]`. Also, the\nprojection into the 2d real and imaginary coordinate planes of trajectory and tube\nis depicted. Every point of the complex-valued signal touches the tube's surface.\n\nThe left plot shows an analytic signal, i.e, the phase difference between\nimaginary and real part is always 90 degrees, resulting in a spiraling trajectory.\nIt can be seen that in this case the real part has also the expected envelope,\ni.e., representing the absolute value of the instantaneous amplitude.\n\nThe right plot shows the real part of that analytic signal being interpreted\nas a complex-vauled signal, i.e., having zero imaginary part. There the resulting\nenvelope is not as smooth as in the analytic case and the instantaneous amplitude\nin the real plane is not recovered. If ``z_re`` had been passed as a real-valued\nsignal, i.e., as ``z_re = z.real`` instead of ``z_re = z.real + 0j``, the result\nwould have been identical to the left plot. The reason for this is that real-valued\nsignals are interpreted as being the real part of a complex-valued analytic signal.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.signal.windows import gaussian\nfrom scipy.signal import envelope\nn, T = 1000, 1/1000  # number of samples and sampling interval\nt = np.arange(n) * T  # time stamps for 1 s duration\nf_c = 3  # Carrier frequency for signal\nz = gaussian(len(t), 0.3/T) * np.exp(2j*np.pi*f_c*t)  # analytic signal\nz_re = z.real + 0j  # complex signal with zero imaginary part\ne_a, e_r = (envelope(z_, (None, None), residual=None) for z_ in (z, z_re))\nE2d_t, E2_amp = np.meshgrid(t, [-1, 1])\nE2d_1 = np.ones_like(E2_amp)\nE3d_t, E3d_phi = np.meshgrid(t, np.linspace(-np.pi, np.pi, 300))\nma = 1.8  # maximum axis values in real and imaginary direction\nfg0 = plt.figure(figsize=(6.2, 4.))\nax00 = fg0.add_subplot(1, 2, 1, projection='3d')\nax01 = fg0.add_subplot(1, 2, 2, projection='3d', sharex=ax00,\n                       sharey=ax00, sharez=ax00)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax00.set_title(\"Analytic Signal\")\nax00.set(xlim=(0, 1), ylim=(-ma, ma), zlim=(-ma, ma))\nax01.set_title(\"Real-valued Signal\")\nfor z_, e_, ax_ in zip((z, z.real), (e_a, e_r), (ax00, ax01)):\n    ax_.set(xlabel=\"Time $t$\", ylabel=\"Real Amp. $x(t)$\",\n            zlabel=\"Imag. Amp. $y(t)$\")\n    ax_.plot(t, z_.real, 'C0-', zs=-ma, zdir='z', alpha=0.5, label=\"Real\")\n    ax_.plot_surface(E2d_t, e_*E2_amp, -ma*E2d_1, color='C1', alpha=0.25)\n    ax_.plot(t, z_.imag, 'C0-', zs=+ma, zdir='y', alpha=0.5, label=\"Imag.\")\n    ax_.plot_surface(E2d_t, ma*E2d_1, e_*E2_amp, color='C1', alpha=0.25)\n    ax_.plot(t, z_.real, z_.imag, 'C0-', label=\"Signal\")\n    ax_.plot_surface(E3d_t, e_*np.cos(E3d_phi), e_*np.sin(E3d_phi),\n                     color='C1', alpha=0.5, shade=True, label=\"Envelope\")\n    ax_.view_init(elev=22.7, azim=-114.3)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fg0.subplots_adjust(left=0.08, right=0.97, wspace=0.15)\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-2851956669117ab4.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "hilbert",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "hilbert"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute analytic signal by means of Hilbert transform."
            }
          ]
        }
      ],
      "type": "func"
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "z",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "bp_in",
        "annotation": "tuple[int | None, int | None]",
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "(1, None)"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n_out",
        "annotation": "int | None",
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "squared",
        "annotation": "bool",
        "kind": "KEYWORD_ONLY",
        "default": "False"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "residual",
        "annotation": "Literal['lowpass', 'all', None]",
        "kind": "KEYWORD_ONLY",
        "default": "lowpass"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": "int",
        "kind": "KEYWORD_ONLY",
        "default": "-1"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "envelope"
  },
  "references": [
    ".. [1] \"Analytic Signal\", Wikipedia,",
    "   https://en.wikipedia.org/wiki/Analytic_signal",
    ".. [2] Lyons, Richard, \"Digital envelope detection: The good, the bad, and the",
    "   ugly\", IEEE Signal Processing Magazine 34.4 (2017): 183-187.",
    "   `PDF <https://community.infineon.com/gfawx74859/attachments/gfawx74859/psoc135/46469/1/R.%20Lyons_envelope_detection_v3.pdf>`__",
    ".. [3] T.G. Kincaid, \"The complex representation of signals.\",",
    "   TIS R67# MH5, General Electric Co. (1966).",
    "   `PDF <https://apps.dtic.mil/sti/tr/pdf/ADA953296.pdf>`__",
    ".. [4] \"Envelope (mathematics)\", Wikipedia,",
    "   https://en.wikipedia.org/wiki/Envelope_(mathematics)",
    ".. [5] Yang, Yanli. \"A signal theoretic approach for envelope analysis of",
    "   real-valued signals.\" IEEE Access 5 (2017): 5623-5630.",
    "   `PDF <https://ieeexplore.ieee.org/iel7/6287639/6514899/07891054.pdf>`__"
  ],
  "qa": "scipy.signal._signaltools:envelope",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "bp_in",
    "n_out",
    "residual",
    "squared",
    "z"
  ]
}