weixin_39747577 2020-11-20 11:47
浏览 0

detrending by fitting a linear function

Before adding this to obspy, I decided put it here for discussion, maybe there is some problem I did not anticipate:

For now, detrending is done using the first and last and last value of the trace in obspy.signal.invsim.detrend. This fails with a lot of noise or when the time window of the trace contains only part of the signal. Wouldn't it be better to fit a linear function to the trace and remove that from the data? E.g. like this:

{{{ for tr in st: dt = tr.stats.delta t = np.linspace(0., (tr.stats.npts - 1) * dt, tr.stats.npts)


A = np.vstack([t, np.ones(len(t))]).T
m, c = np.linalg.lstsq(A, tr.data)[0]

tr.data = tr.data - m*t - c

}}}

Works fine for me.

Cheers, Martin

该提问来源于开源项目:obspy/obspy

  • 写回答

19条回答 默认 最新

  • weixin_39747577 2020-11-20 11:47
    关注

    [barsch] I can't answer from a scientific view as I'm not really into in signal processing. However as far as I know its always going down to the question what you actually want to to with your data. Some prefer method x to do something while some prefer something else.

    Therefore I would suggest to include "your" detrending function as an addition into obspy.signal - either by introducing a new keyword "method=..."to the current detrend function or giving it a completely new name - pretty much the same we did with xcorr, merge etc.

    just my 2 cents Robert

    评论
编辑
预览

报告相同问题?