Log in

View Full Version : A different approach to truncated sinc filters


Katie Boundary
5th September 2018, 08:05
AVIsynth's built-in sinc filter is designed to truncate at an integer number of taps. This leaves filter shapes that need to be "normalized" because their integrals don't equal 1. But has anyone looked into truncating the filter at x-values that leave a filter shape with an integral of exactly 1?

So |x| =
0.61320733549
1.55775636508
2.53778369874
3.52784055722

and so on?

wonkey_monkey
5th September 2018, 09:50
AVIsynth's built-in sinc filter is designed to truncate at an integer number of taps.

As opposed to what? A non-integer number?

Sinc is an infinite filter. It will never add up to 1 in all finite cases.

And it's not the integral you want to equal 1, it's the sum of the particular coefficients that get picked, and those depend on your sampling position.

So |x| =
0.61320733549
1.55775636508
2.53778369874
3.52784055722

and so on?

The more I read this the more I suspect you don't have any understanding of how interpolation filters work.

Then again maybe I'm still blocked for daring to question your brilliance last time, so if anyone who isn't on the Naughty List wants to quote this...

Katie Boundary
5th September 2018, 17:27
This message is hidden because davidhorman is on your ignore list.

Thank you for your input.

TheFluff
5th September 2018, 18:11
I'm a bit confused by your terminology and I'm not a DSP guru, but as far as I understand it, if you want a sinc filter where the coeffs sum to exactly 1, you pretty much want Lanczos, because that's pretty much what Lanczos is. Getting the coeffs to sum to exactly 1 in a real implementation (of any resizer) with all its pesky numerical precision issues requires dithering them though, and even then there might still be a small residual error. See for example zimg's take on it (https://github.com/sekrit-twc/zimg/blob/master/src/zimg/resize/filter.cpp#L89).

wonkey_monkey
5th September 2018, 19:01
Thank you for your input.

If you must be condescending when someone does their best to answer your questions, you should really only do so when you know what you're talking about.

You don't.

Furthermore, most of your "contributions" to this forum seem to consist of little more than insulting other members and spurning their advice, always given in good faith. You're dragging this forum down with your childishness and it's both pathetic and pitiful.

Katie Boundary
5th September 2018, 20:15
I'm a bit confused by your terminology and I'm not a DSP guru, but as far as I understand it, if you want a sinc filter where the coeffs sum to exactly 1, you pretty much want Lanczos, because that's pretty much what Lanczos is.

Lanczos is a windowed sinc filter. I'm referring to truncated sinc, where it just gets cut off abruptly instead of tapering. But you bring up an interesting tangent: In some tests that I ran last night on Desmos, I did notice that Lanczos filters had integrals of pretty damn close to 1 for any number of taps 2 or greater. I expect this to be true of other windowed sinc filters as well. Even at only one tap, the integral was about 0.9

See for example zimg's take on it (https://github.com/sekrit-twc/zimg/blob/master/src/zimg/resize/filter.cpp#L89).

That looks a lot like C code, but isn't C supposed to start with "#include <stdio.h>" and have a "main int" somewhere? :p

TheFluff
5th September 2018, 22:42
As davidhorman mentioned (see below for the record), if you want the coeffs for a sinc filter to sum to exactly 1 then you need an infinitely large filter kernel, so the question in the OP is nonsensical. If you want the coeffs to sum to exactly 1 then you can't just leave some of them out (which is what you do by only considering a fixed number of taps - the mathematically pure sinc filter has an infinite number of taps). So, as I said, the way you solve this is to use a window function because infinitely large filter kernels are obviously not practical, and the best way to do that windowing that anyone has come up with is Lanczos, and that's the only answer I can give you other than "you can't do that".

AVIsynth's built-in sinc filter is designed to truncate at an integer number of taps.
As opposed to what? A non-integer number?

Sinc is an infinite filter. It will never add up to 1 in all finite cases.

And it's not the integral you want to equal 1, it's the sum of the particular coefficients that get picked, and those depend on your sampling position.

So |x| =
0.61320733549
1.55775636508
2.53778369874
3.52784055722

and so on?

The more I read this the more I suspect you don't have any understanding of how interpolation filters work.

Then again maybe I'm still blocked for daring to question your brilliance last time, so if anyone who isn't on the Naughty List wants to quote this...

Katie Boundary
6th September 2018, 17:16
As davidhorman mentioned (see below for the record), if you want the coeffs...

I didn't say anything about coeffs. I said the integral.

wonkey_monkey
6th September 2018, 19:00
I didn't say anything about coeffs. I said the integral.

Why? What significance does the integral have?

Pass this on if you would, Fluff ;)

TheFluff
7th September 2018, 00:46
I didn't say anything about coeffs. I said the integral.

I don't understand what you mean. Perhaps you can elaborate on your line of reasoning?

FranceBB
8th September 2018, 22:52
That looks a lot like C code

Almost. It's C++. ^_^


but isn't C supposed to start with "#include <stdio.h>"


There's no need to include standard input output unless you need to.
It already includes a bunch of things needed for the calculations it has to do:


#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <stdexcept>
#include <vector>


And... in the code linked by TheFluff, the rounding is done (lines 93-115) using double and then float, trying to minimize the error.

Katie Boundary
10th September 2018, 17:31
I don't understand what you mean. Perhaps you can elaborate on your line of reasoning?

Just wondering if there's anything particularly magical about filter shapes with an integral of exactly 1, and if so, what the implications are for truncated (NOT windowed) sinc filters.