Instantaneous magnitude
The Hann Window Kernel is the FFT of the Hann Window.

Offset is defined strangely, and unnecessarily. calculating InstFreqs and then dividing it by Sampling Frequency Fs is just throwing away the work of attaining it.

Bin Resolution = Fs / N
//InstFreqs will start at 0Hz and peak at Fs Hz (or half that??)
InstFreqs(i) = i * Fs / N


So in the referenced answer:

Offset = abs(InstFreqs(i) / (Fs/N) - i)


but if I'm correct that: InstFreqs(i) = i * Fs / N then:

Offset = abs(InstFreqs(i) / (Fs/N) - i) = abs( i - i ) = 0


So that line didn't make sense. Too bad there was no comment hinting at what it was supposed to mean.

index is put into Wk it must span the length of the Window, and not the length of the FFT. So let's start by changing that. N * Offset will (likely) exceed the length of M (window size)

index = floor(abs(Offset) * N) + 1
InstMag = Mag(i) * Wk(index)


Unless of course I misinterpreted what InstFreqs(i) is, which it seems I have.