I've been writing about how a "sliding" trend may function as a estimate of derivative (and what might be better)
here,
here and
here. There has been discussion, particularly commenter Greg. This post just catches up on some things that arose.
Welch smoothing and spherical Bessel functions.
In the first post, I gave
this plot of the spectra of the 10-year OLS trend operator, and what results if multiplied by a Welch taper W, and then multiply again. I'll explain why those operations below. T the spectra are actually
spherical Bessel functions. Or, more exactly,
(π²/3)*(w/2)^(.5-n)*Γ(n+1.5)*J
n+.5(x)
where x=f*π*T, f=freq in 1/Cen, T=trend period,n=1,2,3...
I've given a detailed derivation
here. You might think that Bessel functions is overkill. But in fact, j
0(x)= sqrt(π/2x)J
1/2(x) is just the sinc function sin(x)/x, and as j
n increase in order, they are just trig functions multiplied by polynomials in 1/x, in such a was that they are O(x
n) near 0, and decay as 1/x for large x. So x
1-nj
n has the appropriate asymptotics here, and for the order of the polynomials, uniquely so.
General remarks on filters
Greg has been commenting on the merits of other filters, including Gaussian and Lanczos. They are of course not strictly differentiating filters, but could be converted to one. In fact, any of the usual symmetric windows/filters can be converted by differentiating to a differentiating filter (the reason is not quite as obvious as it sounds).
Properties that you are likely to want in a lowish pass convolution filter are:
- In the time domain, a bounded domain (compact support). In fact, the domain should about match the period corresponding to the upper limit of frequencies that you want to start attenuating.
- In the frequency domain, eventual rapid attenuation with high frequency, which often means controlling side lobes
- Sometimes overlooked, a contrary wish for some specific behaviour in the pass band. Possibly a flat response for low pass, or in our case, an accurate derivative representation.
I say contrary, because whatever is wanted for low frequencies is unlikely to include attentuation. So there is an uncomfortable intermediate region which is neither accurate nor attenuated. This is worse for differentiation filters which want to increase amplitude with frequency right up to the transition to attenuation.
The ideal filter with compact support and bounded domain is that gate or boxcar filter H(t). But in the frequency domain is a sinc function sin(ω)/ω, which attenuates very slowly. There is a rule about rates of attenuation. The power |ω|
-n of attenuation is determined by n, the order of the first derivative that fails to exist. This is usually determined by the cut-off at the ends of the compact support of the filter. H(t) is discontinuous, to the first derivative fails.
There are filters, like Welch, or the triangle filters (see
Wiki for a list) which terminate with a discontinuous derivative. These attenuate O(|ω|
-2). It is fairly easy to extend to a zero derivative at the end, as with Hann, Blackman, and so increase n to 3 or beyond. These satisfy 1 and 2. For Welch W, raising it to the n
th power improves the termination by a power of n, and the corresponding HF attenuation.
The ultimate in this direction is the Gaussian. It gives best roll-off in the freq domain (FD). It does not strictly have bounded support, but approaches zero so fast that it can be truncated, with only a small amplitude HF tail (though slowly fading). This can be ameliorated. But again, it does not have a flat top.
The
Lanczos window tries more to honor requirement 3 by reintroducing aspects of the sinc function in the time domain. It is a product of a narrow and a wider sinc, generally arranged so that the zeroes coincide at the cut-off. It gives a flatter top in the FD, at the cost of being non-positive in the TD.
I find that Welch functions are flexible. You can raise them to any power to give faster attenuation, at the expense of a broader footprint in the FD relative to the support in the TD (so attenuation is eventually faster, but starts later).
Plots
That was all a longish preamble to fulfilling a request from Greg to plot spectra of the Gaussian (truncated at 3 σ), and Lanczos, along with the Welch functions I have been using.
So here are the plots of the windows. I've normalised to area=1, except for Lanczos, shown with area=0.5 (for the sake of the y-axis). But it is restored for the spectrum.
W stands for Welch. You can see that the higher powers are looking quite like the Gaussian. So here are the spectra:
You can see the trade-offs. W decays relatively slowly, but is narrowest in the FD - for its TD footprint, it has a narrower low-pass. Higher powers approach the Gaussian. The Lanczos does indeed have a flatter top, as intended, and also a good attenuation. But it is broadest of all - it lets through relatively high frequencies before the cut-off.