DSP.jl icon indicating copy to clipboard operation
DSP.jl copied to clipboard

resample artifact when end points far from zero

Open igmmgi opened this issue 5 years ago • 3 comments

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?

igmmgi avatar Nov 15 '18 08:11 igmmgi

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?

sirtom67 avatar Nov 19 '18 01:11 sirtom67

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?

igmmgi avatar Nov 19 '18 07:11 igmmgi

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.

ssfrr avatar Nov 20 '18 01:11 ssfrr