Open zhaotingchen opened 6 days ago
If you change the simulation to lognormal then the behaviour becomes harder to track but the idea is the same. I suspect it also relates to #12
@zhaotingchen thanks for pointing this out. I think this is a duplicate of https://github.com/steven-murray/powerbox/issues/10, and I had a branch that attempted to fix that, but it got lost amongst other work I had to do in the meantime. Does that issue look like the same issue you're having? And do the arguments there make sense?
When writing some tests I noticed the power spectrum amplitude is incorrect for odd
pb.N
but correct for even. A code snippet to reproduce the wrong behaviour:You will see that for even
N
, the power is correct, whereas for oddN
the power is exactly half of the input.The issue seems to be that the Fourier conventions between Hermitian random array
delta_k
and thedft.ifft
are not matching. To see that:When
Nbox
is 100, both output gives 1 which is desired. WhenNbox
is 101 on the other hand, the first output is 0.5. To see why, we can check the ifft ofdelta_k
:For
Nbox=100
, the imaginary component is small (but non-zero, maybe due to clipping the last element indelta_k
when even?). ForNbox=101
, thedelta_x
in the code is actually not real-valued but simply set to real later. Half of the amplitude is probably discarded here.This does not give me a good idea how to fix it though. I do not understand why the even case works. But somewhere the Fourier convention must be messed up I think. I did check the code for
dft
and can't spot anything wrong, although I do not understand what is the purpose of_adjust_phase
.