I am using the following formula to calculate the Hann values for a set of points: $$ w(n)=0.5\left(1-\cos\left(2\pi \frac nN\right)\right) $$
To implement this in java, I am using the following code:
private static void applyHannWindow(final double[] points) {
for (int i = 0; i < points.length; i++) {
points[i] = 0.5 * (1.0 - Math.cos(2.0 * Math.PI * points[i] / points.length));
}
}
To take the inverse, solve for $n$, I can re-use the $w(n)$ . Hence, the equation I come up with is this: $$ n = \frac{1}{2\pi}\arccos\big(-2w(n) + 1\big) $$
To implement this in Java, I am using the following code:
private static void reverseHannWindow(final double[] points) {
for (int i = 0; i < points.length; i++) {
points[i] = points.length * (Math.acos(-2.0 * points[i] + 1.0) / (2.0 * Math.PI));
}
}
I wrote a simple test to make sure that after I apply the Hann window, and take it's inverse, that I get the same thing. However, I seem not to.
Given the original array:
final double[] data = new double[5];
data[0] = 200;
data[1] = 210;
data[2] = 215;
data[3] = 207;
data[4] = 203;
I get the following output:
### applying Hann window
0.0
0.0
0.0
0.9045084971874686
0.9045084971874787
### Reversing Hann window
0.0
0.0
0.0
1.9999999999999862
2.0000000000000138
Not sure what I am doing wrong here in applying the inverse to the Hann window?