BUG: iircomb peaking behavior doesn't match documentation
See original GitHub issueDescribe your issue.
The second example in the documentation for signal.iircomb
says:
f0 = 250.0 # Frequency to be retained (Hz)
But this is not the frequency to be retained, it’s the frequency that is cut:
Likewise the parameter w0
says:
Frequency to attenuate (notching) or boost (peaking).
which is incorrect. With ftype='peak'
, 250 Hz is not boosted.
Comb filters do support peaking and notching at both types of frequencies, by varying the sign of the last coefficients, and I would like to support all four configurations in SciPy:
b = [0.0498, 0, 0, 0, -0.0498], a = [1, 0, 0, 0, 0.9]
b = [0.0498, 0, 0, 0, 0.0498], a = [1, 0, 0, 0, -0.9]
b = [0.95, 0, 0, 0, -0.95], a = [1, 0, 0, 0, -0.9]
b = [0.95, 0, 0, 0, 0.95], a = [1, 0, 0, 0, 0.9]
However, I’m not sure what the best interface is. I’m not sure if this counts as a bug in the documentation or a bug in the code.
- If we consider it a bug in the code, then we could change the functionality to match the documentation, so that peaking and notching both occur on the frequency specified (which seems more natural to me), and then add another parameter (
shift
?invert
?) that shifts to the “between frequencies” whenTrue
. - If we consider the documentation to be the bug, then the behavior is kind of strange, but I guess we’d add some other parameter to get the other two behaviors (notching between specified frequency, peaking at specified frequency).
- Or there could be four
ftype
options for the two notching and two peaking variants? Withpeak
andnotch
kept undocumented for backwards compatibility? But I don’t know what to call the other four options.peak_at
andpeak_between
or something?
Reproducing Code Example
fs = 1000.0 # Sample frequency (Hz)
f0 = 250.0 # Frequency to be retained (Hz)
Q = 30.0 # Quality factor
# Design peaking filter
b, a = signal.iircomb(f0, Q, ftype='peak', fs=fs)
# Frequency response
freq, h = signal.freqz(b, a, fs=fs)
response = abs(h)
# To avoid divide by zero when graphing
response[response == 0] = 1e-20
# Plot
fig, ax = plt.subplots(2, 1, figsize=(8, 6))
ax[0].plot(freq, 20*np.log10(np.maximum(abs(h), 1e-5)), color='blue')
ax[0].set_title("Frequency Response")
ax[0].set_ylabel("Amplitude (dB)", color='blue')
ax[0].set_xlim([0, 500])
ax[0].set_ylim([-80, 10])
ax[0].grid()
ax[1].plot(freq, np.unwrap(np.angle(h))*180/np.pi, color='green')
ax[1].set_ylabel("Angle (degrees)", color='green')
ax[1].set_xlabel("Frequency (Hz)")
ax[1].set_xlim([0, 500])
ax[1].set_yticks([-90, -60, -30, 0, 30, 60, 90])
ax[1].set_ylim([-90, 90])
ax[1].grid()
plt.show()
Error message
None
SciPy/NumPy/Python version information
1.7.3 1.20.3 sys.version_info(major=3, minor=7, micro=13, releaselevel=‘final’, serial=0)
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
MIT was we will home can us about if page my has no
... consider northern behind panel floor german buying match default proposed ... minister motion looks fashion directions documentation visitors monitor ...
Read more >Untitled
Keizer ft priester 101 barz, Fit probleem free download, Norvec dili kursu ... 90s board game with phone in middle, Blink 182 scotty...
Read more >DESIGNING FOR SHORT- RUN PRODUCTION - World Radio History
precise electrical matching and careful mechanical align ment, this stereo tandem control allows convenient, single knob adjustment of both channels.
Read more >transcript of speech by minister for foreign affairs george yeo ...
TRANSCRIPT OF SPEECH BY MINISTER FOR FOREIGN AFFAIRS GEORGE YEO AT THEINAUGURAL FULLERTON-SJI LEADERSHIP LECTURE ON 22 JANUARY 2010 AT ...
Read more >19881017.txt - The University of Texas at Austin
Richardson said, "Just because lot you don't doesn't mean your"re a bad team ... MATCHING COUCH ond chair earth tones good condition *150...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
At least for the FIR case it’s a bit weird to get the behavior from a function named
iircomb
, I’d be tempted to make afircomb
. But if we can get all these behaviors from a single function I can live with it being part ofiircomb
even if the impulse response is finite.Can you think of a clean API from scratch that would work for the Wikipedia cases? Maybe we should start from there and then decide if we can make it fit into
iircomb
somehow, or if we should make a separate function / separate functions.Okay thinking about this option more, how about following
firwin
a bit and addpass_zero=False
:Then it’s clear(er) that for either
ftype
, by default, zero will be notched – and hencef0
and its multiples will be notched, too. If you passpass_zero=True
,(f0 * n)/ 2.
will be notched instead.It’s not as pretty as maybe we’d like, but it’s at least internally somewhat consistent (with
firwin
) and avoids any deprecation…