5
$\begingroup$

Bug introduced in 6.0, persisting through 13.3.1.


This is SINC filter, integrate $|H|^2$ from $-\pi/2$ to $\pi/2$.

MMA CODE, Result = 7.27956e-12

ClearAll["Global`*"]
osr = 16;z = E^(I*w);
h = (1-z^-osr)/(1-z^-1)/osr;
N[Integrate[0.5*(Abs[h^5])^2, {w, -π, π}]/(2*π/osr), 5]

MATLAB CODE, Result = 0.2156

clear;clc;
syms w
osr = 16;
z=exp(1j*w);
h=(1-z^-osr)/(1-z^-1)/osr;
vpa(int(0.5*(abs(h^5))^2,-pi,pi)/(2*pi/osr),5)

Further, if increasing OSR=32, MMA will come up with a more outrageous answer; while if decreasing the order to 4, h^4, MMA's result is correct. Could anyone help explain this, thank you!

$\endgroup$
2
  • $\begingroup$ NIntegrate[0.5*(Abs[h^5])^2, {w, -π, π}]/(2*π/osr). $\endgroup$
    – Syed
    Oct 31, 2023 at 1:30
  • $\begingroup$ To close voters, this isn't a simple mistake at all, it's a bug, see my answer below. $\endgroup$
    – xzczd
    Oct 31, 2023 at 2:20

1 Answer 1

8
$\begingroup$

This is a bug introduced in v6. To be precise, a regression is first introduced in v5.1 or v5.2:

enter image description here

enter image description here

Then it evolves to a bug in v6:

enter image description here

As shown by Syed in comment above, if you just need numeric solution, then using NIntegrate instead is a possible work-around:

NIntegrate[1/2 (Abs[h^5])^2, {w, -π, π}]/(2 π/osr)
(* 0.215606 *)

It's also possible to fix the issue in Integrate. We just need ComplexExpand:

osr = 16; z = E^(I*w);
h = (1 - z^-osr)/(1 - z^-1)/osr;
Integrate[1/2 (Abs[h^5])^2 // ComplexExpand, {w, -π, π}]/(2 π/osr)
(* 1852037801/8589934592 *)
N@%
(* 0.215606 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.