BUTTER function returning slightly different results for Signal Processing Toolbox in R2020b and R2021a on same computer (Win10)

6 views (last 30 days)
JS
JS on 6 Jan 2022
Commented: JS on 12 Jan 2022
[numerator, denominator] = butter(9, 0.5 / (100/2), 'high')
The returned numerator coefficients are slightly different for R2021a when compared to output from R2020b on the same Win10 computer. The difference is quite small (on the order of 1E-13) but is resulting in some analysis differences. I get identical coefficient values for R2020b, R2020a or R2019a.
I tried using a technique outlined in an older thread where user appeared to run into a similar issue but differences persist ( https://www.mathworks.com/matlabcentral/answers/98640-why-does-the-butter-function-return-different-results-for-signal-processing-toolbox-4-3-and-5-0 ).
Matlab release notes don't indicate something was changed in BUTTER function for R2021a version.
  3 Comments

Sign in to comment.

Answers (1)

Jan
Jan on 11 Jan 2022
Edited: Jan on 11 Jan 2022
You can compare both results with this cheap implementation of a high pass Butterworth filter:
format long g
[num, den] = butter(9, 0.5 / (100/2), 'high');
[num2, den2] = cheapButterHigh(9, 0.5 / (100/2));
[num.' - num2.' , den.' - den2.']
ans = 10×2
1.0e+00 * -4.44089209850063e-16 0 3.5527136788005e-15 0 -1.4210854715202e-14 0 2.8421709430404e-14 2.8421709430404e-14 -5.6843418860808e-14 -4.2632564145606e-14 5.6843418860808e-14 4.2632564145606e-14 -2.8421709430404e-14 -4.2632564145606e-14 1.4210854715202e-14 2.1316282072803e-14 -3.5527136788005e-15 -5.32907051820075e-15 4.44089209850063e-16 6.66133814775094e-16
function [num, den] = cheapButterHigh(n, W)
% A simple high pass Butterworth implementation.
% Jan, Heidelberg, CC BY-SA 3.0
V = tan(W * 1.5707963267948966); % pi/2
Q = exp((1.5707963267948966i / n) * ((2 + n - 1):2:(3 * n - 1)));
Sg = 1 ./ prod(-Q);
Sp = V ./ Q;
% Bilinear transform:
P = (1 + Sp) ./ (1 - Sp);
G = real(Sg / prod(1 - Sp));
Z = ones(length(Q), 1);
% From Zeros, Poles and Gain to B (numerator) and A (denominator):
num = G * real(poly(Z));
den = real(poly(P));
end
For large n this implementation is assumed to be less stable than Matlab's version, but I need it for n < 12 only.
Although this cheaper version is 10 times faster, it is not thought to save run time: Usually a program does not need tenthousands of different filter parameters.
  1 Comment
JS
JS on 12 Jan 2022
Thank you for posting this. Your implementation is giving consistent coefficient values for R2021a and previous versions which will be useful for running comparisons. I reached out to Matlab in the meantime to get a better understanding of implemented changes for R2021a (and newer versions) and will post update when available.

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by