0

Please see sample code below for usage of filter function in Matlab. For truncated input, I expected to get exact result up to the truncate point, but there are tiny differences, although it is within double precision. Is this expected behavior?

X = randn(10000,1);
b = ones(1, 500) / 500;
Y = filter(b,1,X);
Y1 = filter(b,1,X(1:end-1));
tmpdiff = Y(1:end-1)-Y1;
sum(abs(tmpdiff)) % not equal to zero; in the order of 10^(-16)
plot(tmpdiff)  % some spikes
ahala
  • 4,683
  • 5
  • 27
  • 36
  • “within double precision”. If you compute something in two different ways, you should expect rounding errors to cause differences. Just changing the order of additions will do this. – Cris Luengo Jul 01 '20 at 20:10
  • or create a filter object where you specify the word length of the input, output and of the coefficients – Irreducible Jul 02 '20 at 06:07

1 Answers1

1

One should expect identical results for truncated inputs, the nonzero discrepancies in the question are not ideal and could be avoided. The problem is the MKL code branch used. When checking the MKL version, I got:

Intel(R) Math Kernel Library Version 2018.0.3 Product Build 20180406 for Intel(R) 64 architecture applications, CNR branch AVX2

By setting an environment variable MKL_DEBUG_CPU_TYPE=4, the CNR branch is switched to AVX, and the nonzero results are gone.

ahala
  • 4,683
  • 5
  • 27
  • 36