Window functions and indexes larger than N/2
The window is defined as $-N/2 \le n \le N/2$ i.e. symmetric about $n=0$.

So, for a 1024 window size, $n=-512$ to $n=+511$ should give you the appropriate coefficients.