# GaussianFilter misbehave at large smoothing radii?

Context

Straight from the documentation of GaussianFilter, If one generates a time series and smooth it one gets

res = Table[GaussianFilter[ts, r], {r, {10, 50, 100}}];
ListLinePlot[Join[{ts}, res],
PlotLegends -> {"data", "r = 10", "r = 50", "r = 100"}]


(if you want to generate random data you could use data = RandomFunction[WienerProcess[], {0, 1, 0.01}])

Problem

But if I extend the smoothing range from the example (admittedly in a rather unrealistic regime but bear with me)

data // Table[
ListLinePlot[
GaussianFilter[#, 10^R, Method -> "Gaussian",
Padding -> "Periodic"]], {R, 1, 4, 1/4}] &


So you can see something rather odd which is that at larger smoothing radii the curve become less smooth (i.e it shows more local extrema)!

Question

Could you please confirm that this is a bug?

Workaround

FYI, a workaround is to use Fourier Filtering

fftIndgen[size_] := 2. Pi/ size ArrayPad[
Range[0, Quotient[size, 2]],
{0, Quotient[size, 2] - 1},
"ReflectedNegation"];
FourierGaussianFilter[data_, R_] :=
InverseFourier[Fourier[data]*Exp[-1/2 R^2
fftIndgen[Length[data]]^2]] // Re // Chop


Then with

I get

 data//Table[ListLinePlot[FourierGaussianFilter[#, 10^R]],
{R, 1, 4, 1/4}] &


So in terms of diagnostic, one can visually see that GaussianFilter produces a growing number of extrema as a function of smoothing past a given threshold, whereas FourierGaussianFilter does not. IMHO the latter is behaving correctly in that regime, whereas the former does not. Note that this discrepancy can be made quantitative e.g. for Gaussian random fields, since there is a prediction for this number as a function of smoothing scale $$R$$ (i.e. it should scale like $$1/R$$).

• Looking at the decreasing scale on the vertical axes, it's not clear to me that the curves are becoming less smooth. It does seem to me the series is approaching the mean of the data. Just how is smoothness measured? – Michael E2 May 7 '20 at 12:49
• extrema identification – chris May 7 '20 at 13:50
• I kinda thought it was supposed to reduce the variation/variance of something or other. But I don't know the formula. – Michael E2 May 7 '20 at 14:07
• As Michael E2 said isn't it just the scale? If you fix the plot range then everything is smooth:data // Table[ ListLinePlot[ GaussianFilter[#, 10^R, Method -> "Gaussian", Padding -> "Periodic"], PlotRange -> {Min[data], Max[data]}], {R, 1, 4, 1/4}] & – demm May 7 '20 at 16:32
• Does using Padding -> "Fixed" get you what you think you should get. Using Padding -> "Periodic" is probably not what you want. – JimB May 12 '20 at 22:28

## 1 Answer

I think it's that the option Padding -> "Periodic" doesn't get the behavior you want. Using Padding -> "Fixed" is probably what you want.

Here are the results using different scales for each radius:

SeedRandom[12345];
data = RandomFunction[WienerProcess[], {0, 1, 0.001}]
data // Table[ListLinePlot[GaussianFilter[#, 10^R, Method -> "Gaussian", Padding -> "Fixed"],
PlotLabel -> "R = " <> ToString[10.^R]], {R, 1, 4, 1/4}] &


Now with same scales: