1
b, a = butter(order, normal_cutoff, btype='low', analog=False)
  • 这突出了黄油,并说有太多的价值要打开。当我运行代码时,它可以工作并且不返回任何错误。
b, a, c = butter(order, normal_cutoff, btype='low', analog=False)
  • 这没有突出显示,但是当我运行代码时它会中断,因为它期望黄油有 3 个输出,但只有 2 个。

我觉得这很奇怪,因为在第一种情况下我不应该得到任何错误,但它仍然在对我大喊关于太多的值......所以我给它更多的值来输出,它破坏了我的代码。有什么见解吗?

4

1 回答 1

0

的返回值butter取决于output函数参数,默认为'ba'. 无论是“突出显示”您的代码,都没有考虑输出值的可变性质,这解释了代码运行正确的原因。

该文档清楚地描述了可能的不同返回值:

>>> help(scipy.signal.butter)
Help on function butter in module scipy.signal.filter_design:

butter(N, Wn, btype='low', analog=False, output='ba', fs=None)
    Butterworth digital and analog filter design.
...
    Returns
    -------
    b, a : ndarray, ndarray
        Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
        Only returned if ``output='ba'``.
    z, p, k : ndarray, ndarray, float
        Zeros, poles, and system gain of the IIR filter transfer
        function.  Only returned if ``output='zpk'``.
    sos : ndarray
        Second-order sections representation of the IIR filter.
        Only returned if ``output=='sos'``.
于 2021-09-02T21:06:08.343 回答