{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For the signal "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "y = (y_1, y_2, \\ldots, y_n)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and weights "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "w = (w_1, w_2, \\ldots, w_n)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", WH of order "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with smoothing or penalty parameter "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\lambda"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " solves the following optimization problem for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\operatorname{argmin}_{x_i} \\sum_i^n w_i (y_i - x_i)^2\n+ \\lambda \\sum_i^{n-p} (\\Delta^p x_i)^2 \\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\Delta^p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the forward difference operator of order "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\Delta x_i = x_{i+1} - x_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\Delta^2 x_i = \\Delta(\\Delta x_i) = x_{i+2} - 2x_{i+1} + x_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For every input value "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "y_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", it generates a smoothed value "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "One of the nice properties of WH is that it automatically performs inter- and extrapolation of data. Interpolation means filling in values when signal data is only available on the left and on the right. Extrapolation means filling in values after the observed signal ends. Set "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "weights = 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for regions where you want to extra- or interpolate. The values of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "signal"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " don't matter if "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "weights = 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". WH interpolates a polynomial of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "degree = 2 * order - 1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and it extrapolates a polynomial of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "degree = order - 1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "order = 2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", this means cubic interpolation and linear extrapolation."
            }
          ]
        }
      ],
      "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": "res",
              "annotation": "_RichResult",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An object similar to an instance of "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.optimize.OptimizeResult",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.optimize._optimize:OptimizeResult"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with the following attributes:"
                    }
                  ]
                },
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "x"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "The WH smoothed signal."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "lamb"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "The penalty parameter. If the input "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "lamb"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is a number, this value is     returned. If the input was "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "\"reml\""
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": ", the penalty parameter that minimized     the REML criterion is returned."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Whittaker-Henderson (WH) smoothing/graduation of a discrete 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": "signal",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A one-dimensional array of length "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "order + 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " representing equidistant data points of a signal, e.g. a time series with constant time lag."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "lamb",
              "annotation": "str or float, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Smoothing or penalty parameter, default is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "\"reml\""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " which minimizes the restricted maximum likelihood (REML) criterion to find the parameter "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lamb"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If a number is passed, it must be non-negative and it is used directly."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "order",
              "annotation": "int, default: 2",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The order of the difference penalty, must be at least 1."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "weights",
              "annotation": "array_like or None, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A one-dimensional array of case weights with the same length as "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "signal"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is equivalent to an array of all ones, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.ones_like(signal)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This implements WH smoothing with a difference penalty of the specified "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "order"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and penalty strength "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "lamb"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", see "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". WH can be seen as a penalized B-Spline (P-Spline) of degree zero for equidistant knots at the signal positions."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In econometrics, the WH graduation of order 2 is referred to as the Hodrick-Prescott filter "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "4"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "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": "build-install/usr/lib/python3.14/site-packages/scipy/signal/_whittaker.py",
  "item_line": 67,
  "item_type": "function",
  "aliases": [
    "scipy.signal.whittaker_henderson"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "We use data from https://data.giss.nasa.gov/gistemp/ for global temperature\nanomalies, i.e., deviations from the corresponding 1951-1980 means (Combined\nLand-Surface Air and Sea-Surface Water Temperature Anomalies, Land-Ocean Temperature\nIndex, L-OTI).\nWe use weights to indicate where to inter- and extrapolate the missing data.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from pathlib import Path\nimport numpy as np\nimport scipy\nfrom scipy.signal import whittaker_henderson\n# For the most recent data, use\n# fname=\"https://data.giss.nasa.gov/gistemp/tabledata_v4/GLB.Ts+dSST.csv\"\n# Here, we instead use a copy made in 2026.\nfname = Path(scipy.signal.__file__).parent / \"tests/data/GLB.Ts+dSST.csv\"\ndata = np.genfromtxt(\n    fname=fname,\n    delimiter=\",\", skip_header=2, missing_values=\"***\"\n)\nyear = data[:, 0]\ntemperature = data[:, 1:13].ravel()  # monthly temperature anomalies\nw = np.ones_like(temperature)\n# We might have some nan values.\nnp.sum(np.isnan(temperature))\nw[np.isnan(temperature)] = 0\nres = whittaker_henderson(temperature, weights=w)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "temperature[:5]\nres.x[:5]\n",
        "execution_status": "failure",
        "out": "array([-0.18, -0.18, -0.17, -0.17, -0.17])\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nLet us plot measurements and Whittaker-Henderson smoothing.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\nx = year[0] + np.arange(len(temperature)) / 12\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.plot(x, temperature, label=\"measurement\")\nplt.plot(x, res.x, label=\"WH smooth\")\n# Above, we set w = 0 for nan values of temperature. WH automatically\n# inter- or extrapolates for all data points with w = 0.\nplt.plot(x[w==0], res.x[w==0], color=\"red\", label=\"inter-/extrapolation\")\nplt.xlabel(\"year\")\nplt.ylabel(\"temperature deviation [°C]\")\nplt.title(\"Global Temperature Anomalies (ref. 1951-1980)\")\nplt.legend()\n",
        "execution_status": "failure",
        "out": "<matplotlib.legend.Legend object at 0x7f3f607946e0>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "2.0.0.dev0+git20260907.41eeb59",
          "kind": "assets",
          "path": "fig-da1233f539b9a18a.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWe can see that extrapolation has occurred at the right end of the signal, meaning\nthat NaNs existed in the data for the most recent dates, in particular months of\n2026 that have not yet happened at the time of the data download in March 2026."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "signal",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "lamb",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "reml"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "order",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "2"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "weights",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "whittaker_henderson"
  },
  "references": [
    ".. [1] Whittaker-Henderson smoothing,",
    "       https://en.wikipedia.org/wiki/Whittaker%E2%80%93Henderson_smoothing",
    ".. [2] Eilers, P.H.C. (2003).",
    "       \"A perfect smoother\". Analytical Chem. 75, 3631-3636.",
    "       :doi:`10.1021/AC034173T`",
    ".. [3] Weinert, Howard L. (2007).",
    "       \"Efficient computation for Whittaker-Henderson smoothing\".",
    "       Computational Statistics and Data Analysis 52:959-74.",
    "       :doi:`10.1016/j.csda.2006.11.038`",
    ".. [4] Hodrick, R. J., and Prescott, E. C. (1997).",
    "       \"Postwar U.S. Business Cycles: An Empirical Investigation\".",
    "       :doi:`10.2307/2953682`"
  ],
  "qa": "scipy.signal._whittaker:whittaker_henderson",
  "arbitrary": [],
  "local_refs": [
    "lamb",
    "order",
    "res",
    "signal",
    "weights"
  ]
}