DSP.jl
DSP.jl copied to clipboard
resample artifact when end points far from zero
using DSP
using Plots
sig = rand(1000)
plot(resample(sig, 1/2))
plot(resample(sig .+ 100, 1/2))
Am I doing something wrong with the resample function?
Or is the standard solution just to mirror x samples before/after signal before resampling then remove the mirror portion of signal?
Yes and no. The resample function assumes zeros for the signal before and after the signal's domain. A large step - like you have added with the "+ 100" case - will have ringing transients.
Mirroring x samples before and after is a reasonable ad-hoc solution. This is the approach taken in MathWorks' "filtfilt". In many cases it works like magic. But in some cases there are still strange issues.
Can you work with a longer signal and just extract the valid portion from the center afterwards?
Thanks. Yes, currently I just mirror the signal forwards/backwards before calling resample then remove central part after. I wonder if such a mirroring technique would be a useful internal additional option to the function resample within DSP?
It does seem like a useful addition to specify the padding mode. Scipy's filtfilt
has a padtype
argument that can be None
, odd
, even
or constant
. They also support Gustafsson’s method. It also would be worth comparing to the many modes of numpy.pad
Duplicate of #137, but at this point this one has more info, so I'll close that one in favor of this.