# Implementation of SINC filter using Integrate results in incorrect output

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!

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

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

Then it evolves to a bug in v6:

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 *)
`