New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: signal.cheby1: wrong gain and cut-off frequency #20571
Comments
@DietBru maybe you would be interested in taking a look? |
Depending on the application, the way low-pass filters are characterized varies quite a bit and is often inconsistent across the literature. The parametrization of cheby1() adheres to the established conventions (as described in Wikipedia): The allowed ripples are confined to the interval Wikipedia also provides a formula relating the 3 dB cut-off frequency N = 5 # order of filter
rp = 5 # width of ripple band in dB
eps = np.sqrt(10**(rp/10) - 1)
s = np.cosh(1 / np.cosh(1/eps) / N)
b, a = cheby1(N, rp, f_c * s, 'lowpass', analog=True) To obtain unity gain at 0 Hz for even order filters, just multiply the output For practical purposes, I can recommend the nice graphical filter design tool pyFDA which allows interactive twiddling of filter parameters to a required specification. My opinion on modifying cheby1():
|
@DietBru: Thanks for your fast reply. I think, one ore two additional options like cutoff="3dB" and gain="unity" would be nice. Your explanation and sample code should be added to the API reference at https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.cheby1.html. Than additional options are not necessary. |
@rcasperson would you be interested in making a docs PR for this, for @DietBru to review? |
My docs PR is an addition to the notes:
The equiripple passband has N maxima or minima (for example, a 5th-order filter has 3 maxima and 2 minima). Consequently, the DC gain is unity for odd-order filters, or -rp dB for even-order filters. To obtain unity gain at 0 Hz for even-order filters, just multiply the output b by 10**(rp/20) or alternatively a by 10**(-rp/20).
The edge frequency fe of the pass-band is defined as the crossing of the level -rp dB. If the cutoff frequency fc at a level of -3 dB is given, the required edge frequency at -rp can be calculated by fe = fc * s where s = np.cosh(1 / np.cosh(1/eps) / N) and eps = np.sqrt(10**(rp/10) - 1).
Is it the same correction for low pass and high pass or is it fe = fc * s for a low pass and fe = fc / s for a high pass?
Von: Lucas Colley ***@***.***>
Gesendet: Donnerstag, 25. April 2024 11:16
An: scipy/scipy ***@***.***>
Cc: Casperson, Ralf ***@***.***>; Mention ***@***.***>
Betreff: Re: [scipy/scipy] BUG: signal.cheby1: wrong gain and cut-off frequency (Issue #20571)
SICHERHEITSHINWEIS: Diese E-Mail wurde von außerhalb an die BAM gesendet. Bitte klicken Sie nicht auf Links oder öffnen Anhänge, bevor Sie nicht den Absender verifiziert haben und sicher sind, dass der Inhalt vertrauenswürdig ist.
This message was sent from outside of BAM. Please do not click links or open attachments unless you recognize the sender and know the content is trustworthy.
Your explanation and sample code should be added to the API reference
@rcasperson <https://github.com/rcasperson> would you be interested in making a docs PR for this, for @DietBru <https://github.com/DietBru> to review?
—
Reply to this email directly, view it on GitHub <#20571 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AE4VGEM3SYM3FVUKIJ2S3RLY7DCTFAVCNFSM6AAAAABGW3RZZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZWG4ZTGMJVGY> .
You are receiving this because you were mentioned. <https://github.com/notifications/beacon/AE4VGEKPBD3QFGIIK5IDTHDY7DCTFA5CNFSM6AAAAABGW3RZZWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTT3ZBXOI.gif> Message ID: ***@***.*** ***@***.***> >
|
Describe your issue.
At a low pass |G(0)| shall be 0 dB and and |G(fcutoff)| shall be -3 dB according to the definition of the characteristics of a low pass filter.
At scipy.signal.cheby1 |G(0)| is either 0 dB or -rp depending on the order of the filter and |G(fcutoff)| is -rp.
The same issue occurs at cheby1 high pass and band pass filters.
Reproducing Code Example
Error message
SciPy/NumPy/Python version and system information
The text was updated successfully, but these errors were encountered: