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

Resample doesn't resample at given rate

Open dsweber2 opened this issue 6 years ago • 2 comments

For example, simply trying to double the length of a signal doesn't actually work:

x = randn(4)
resample(x,4.0)
resample(x,4//1)

both of which return a vector of length 14. I tried various other lengths for x and got that it down by 2 for every case.

I tried altering the amount of zero padding, but increasing the padding by even 1 led to a length 18 signal. I suspect that something is wrong with the actual resample_filter design, but I'm not knowledgeable enough with the material to fix it on my own at this point.

And while we're at it, not being able to put in an integer as a resampling rate is mildly annoying. Is there any design reason for this?

dsweber2 avatar Oct 30 '17 22:10 dsweber2

Another issue-- both this and the matlab version assume that the signal is periodic (or at least continuous at the boundaries), leading to some pretty nasty gibbs phenomina (e.g. plot([x for x=0:.1:10])). Since this is pretty easy to fix by mirroring the signal (using resample([x; flipdim(x,1)],2.0)), I'm surprised that neither matlab nor this DSP code does this. If there's a speed concern, checking the difference between the first and last entry relative to the mass of the whole signal (e.g. (x1]-x[end])/norm(x)>ϵ should be a sufficient check (if their neighbors are too far from the current, simply mirroring isn't going to cut it).

dsweber2 avatar Oct 31 '17 00:10 dsweber2

I don't think that automatically mirroring the signal is a good idea, as I would want to opt into that if I wanted to actually do that.

However, I agree that allowing the multirate filters to eat some samples isn't good; if I ask for a 2//1 resampling factor, I should get exactly 2x as many samples out. For example, I would expect resample(randn(4), 2//1) to give me the number of output samples as is declared by DSP.outputlength(FIRFilter(h, 2//1), length(x)).

staticfloat avatar Mar 31 '18 00:03 staticfloat