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

6 ビュー (過去 30 日間)
[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 件のコメント
JS
JS 2022 年 1 月 11 日
Thanks for the suggestion (I had mistakenly assumed they would be p-files). There appear to a number of differences in how numerator and denominator coefficients are calculated.
R2021a
p = eig(a);
[z,k] = buttzeros(btype,n1,Wn1,analog,p+0i);
den = real(poly(p));
num = [zeros(1,length(p)-length(z),'like',den) k*real(poly(z))];
R2019a:
den = poly(a);
num = buttnum(btype,n,Wn,Bw,analog,den);
"buttzeros.m" in R2021a and "buttnum.m" in R2019b appear to serve similar purpose but there are differences (and since support functions include .p-files, in-depth debugging is not possible).
Cris LaPierre
Cris LaPierre 2022 年 1 月 11 日
I suggest contacting support. If you receive an answer to your question, consider posting here.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2022 年 1 月 11 日
編集済み: Jan 2022 年 1 月 11 日
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.
  2 件のコメント
JS
JS 2022 年 1 月 12 日
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.
Chris Heyman
Chris Heyman 2023 年 5 月 10 日
Hi JS,
Did you ever recieve a response from Matlab about this?
Thanks
-C

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFilter Analysis についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by