alias-free-torch icon indicating copy to clipboard operation
alias-free-torch copied to clipboard

2D Filter Jinc appears to be wrong

Open torridgristle opened this issue 2 years ago • 3 comments

Here is a plot of the generated 1D sinc filter kernel. sinc looks right

Here is a plot of the generated 2D jinc filter kernel. jinc looks wrong

I'd expect it to look more like a series of rings or ripples, rather than a donut or torus.

jinc filtered noise fft

The FFT output for randn noise put through the 2D filter doesn't look right either.

change jinc to sinc in 2d filter

Changing filter_ = 2 * cutoff * window * jinc(2 * cutoff * time) to filter_ = 2 * cutoff * window * sinc(2 * cutoff * time) in kaiser_jinc_filter2d makes a more familiar kernel.

change jinc to sinc in 2d filter fft out

And the FFT output for randn noise put through this 2D filter looks about how I'd expect.

torridgristle avatar Jul 24 '22 19:07 torridgristle

I really appreciate your great issues!

I did not notice that i1 is modified Bessel function at that time. For now it seems better that replace all wrong jinc as sinc to maintain 2d options.

Please tell me if you have any better idea. Thank you for your issues again!

junjun3518 avatar Jul 24 '22 23:07 junjun3518

SciPy has a Bessel function, scipy.special.j1(). I can't find an implementation of it elsewhere that looks correct when I recreate it.

Edit: There's a Jinc function that keeps to basic Python and PyTorch in rosinality's Alias-Free GAN repo.

torridgristle avatar Jul 27 '22 01:07 torridgristle

Thank you for good references!

Oh, he took polynomial approximation coefficients from outside. Since my first goal is understandable and flexible code with pytorch, sinc is not a bad option for now. In addition, I think that I need more study for jinc for better implementation.

junjun3518 avatar Jul 29 '22 00:07 junjun3518