junjun3518 / alias-free-torch

Simple torch.nn.module implementation of Alias-Free-GAN style filter and resample
Apache License 2.0
86 stars 8 forks source link

2D Filter Jinc appears to be wrong #5

Open torridgristle opened 2 years ago

torridgristle commented 2 years ago

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.

junjun3518 commented 2 years ago

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!

torridgristle commented 2 years ago

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.

junjun3518 commented 2 years ago

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.