-
Notifications
You must be signed in to change notification settings - Fork 86
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
Incorrect filter design for filter gain removal in mag_calc.py #376
Comments
Morning, thanks for looking at this. It looks like you are correct - apologies for this, I clearly didn't look into from scipy.signal import iirfilter, sosfreqz
sos = iirfilter(corners, [lowcut / (0.5 * tr.stats.sampling_rate),
highcut / (0.5 * tr.stats.sampling_rate)],
btype='band', ftype='butter', output='sos')
_, gain = sosfreqz(sos, worN=[1 / period], fs=tr.stats.sampling_rate)
amplitude /= np.abs(gain) |
- Rewrote amp_pick_event for simplicity and clarity - Added tests for accuracy - Implemented correct filter gain look-up for the digital SOS filter applied.
@twinder36 I had a go at fixing this using the method I suggested above using the digital filter in the PR here: #378 It would be great to get your feedback on that. |
No worries @calum-chamberlain, I've been going through all of this with a fine tooth-comb the past few days to finalise the magnitudes module of QuakeMigrate - the magnitudes code in EQcorrscan has provided a useful reference! Having played with the two options a bit it seems there is generally a negligible difference between using the equivalent analog response and reading it from sosfreqz, but yours is the more correct approach. Looks good to me. |
Great, I'm glad it hasn't actually screwed up a workflow - thanks for reporting the issue! QuakeMigrate looks like its coming along well - what more are you guys planning with it? |
When correcting for gain of pre_filt in mag_calc, a digital filter design is used rather than analog, which is not appropriate to look up the filter gain for a given frequency.
In ObsPy the iirfilter designed to apply a butterworth bandpass filter is digital, so that it is suitable to be applied using scipy.signal.sosfilt().
To look up the filter gain for a given frequency (and correct the amplitude observation for this) an analog filter should be used (as expected by the ObsPy response functions).
Current code:
Correct filter design:
See https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.iirfilter.html
The text was updated successfully, but these errors were encountered: