It seems that as a general rule, for digital IIR filters of order more than 2, one is encouraged to use a cascade of second order sections, for reasons connected to the poor stability of high-order filters. See, for example, my question What is the largest "safe" order for the digital Butterworth filter of a given signal? and the answers given there, or the "Limitations" section of https://uk.mathworks.com/help/signal/ref/butter.html.
Now suppose I have a digital signal $x(t)=\sin(2\pi t)$, $t \in \{0,0.08,0.16,\ldots,99.92,100\}$.
Suppose I want to filter this signal in the passband $[f_\mathrm{min},f_\mathrm{max}]=[0.5,3]$ using a zero-phase Butterworth bandpass filter, with filter order $60$; I believe the transfer function of the filter should be $$ H(2\pi if) \ = \ \frac{f^{30}}{f^{30}+\left( 0.4f^2 - 0.6 \right)^{30}} $$ where 0.4=1/(3-0.5) and 0.6=1/((1/0.5)-(1/3)).
Presumably, the correct result for the filtered signal will be almost identical to the original signal.
In MATLAB, I can perform the filter by a cascade of second order sections, using the code
n=15;
Wn=[0.5 3]/6.25;
[z,p,k]=butter(n,Wn);
[sos,g] = zp2sos(z,p,k);
d=filtfilt(sos,g,x);
or I can perform the filter directly from the transfer function coefficients, using the code
n=15;
Wn=[0.5 3]/6.25;
[b,a]=butter(n,Wn);
d=filtfilt(b,a,x);
The results for the two approaches are as follows:
The upper graph gives the result of the SOS approach, and the lower graph gives the result of the direct approach.
It seems that for quite a significant proportion of the duration of the signal (around the start and end), the SOS method is giving considerably inaccurate results.
Why is the direct approach giving (what I presume to be) a much more accurate result overall than the SOS approach? Should some caveats be added to the general advice that one should always use SOS?