Why doesn't the kurtosis function work properly for complex numbers?
9 views (last 30 days)
Guillem Foreman on 20 Sep 2022
I was trying out the kurtosis function on Matlab with complex numbers, using the following code:
var = sqrt(1/2) * randn(1,1000) + 1i * sqrt(1/2) * randn(1,1000);
var_kurt = kurtosis(var);
I was expecting var_kurt to equal 3, since I'm calculating the kurtosis of a gaussian distributed complex function, but instead I get a value of 68.7674 +18.3410i. However, kurtosis(real(var)) does equal 3, which surprises me since the kurtosis should not depend on the variable being complex. Any idea why this happens?
Thanks very much in advance,
David Goodmanson on 20 Sep 2022
Edited: David Goodmanson on 22 Sep 2022
Both the standard deviation and the variance (std and var) work correctly for complex argument, so kurtosis appears to be a bug in the sense that if Matlab does the other two correctly, why not this one?
For complex data the mean stays complex, and the variance is the sum of (absolute distance)^2 from the mean. For
n = 1e6;
y = sqrt(1/2)*randn(1,n) + i*sqrt(1/2)*randn(1,n);
m = mean(y);
vcalc = sum(abs(y-m).^2)/n
v = var(y,1)
v and vcalc are identical.
The variance uses the '1' option because that version is used to find kurtosis. With the '1' option, the variance is
otherwise var divides by (n-1). I wish dividing by n was the default, but somebody else makes the rules.
For kurtosis you need [4th moment about the mean] / [2nd moment about the mean]^2, so the obvious thing to do is
mom2 = sum(abs(y-m).^2)/n % same as vcalc and var(..,1)
mom4 = sum(abs(y-m).^4)/n
kcalc = mom4/mom2^2
k = kurtosis(y)
For real data, these last two agree. For samples from a real normal distribution the kurtosis is close to 3 (not exactly 3 since you are sampling from the distribution) which is correct. For the complex normal distribution used in your code the kurtosis is close to 2, also correct.
As for Matlab kurtosis, it is treating the complex variable just as it would a real variable, which means leaving out the 'abs' in the calculations of the moments above. This leads to a meaningless complex value for kurtosis.