As mentioned in the numpy documentation, numpy.fft.irfft requires the length of the original signal for a proper reconstruction, otherwise an original signal of even length is assumed. Therefore, to achieve identity of the reconstruction for the above signals, it is necessary to call:
# get spectrum
Xe = np.fft.rfft(xe)
Xo = np.fft.rfft(xo)
# recover signal
xe_reconstructed = np.fft.irfft(Xe, n=xe.size)
xo_reconstructed = np.fft.irfft(Xo, n=xo.size)
# bad way of recovering
xe_reconstructed_not_good = np.fft.irfft(Xe) # yields correct result, bc. original signal is even
xo_reconstructed_not_good = np.fft.irfft(Xo) # yields wrong result, bc. original signal is odd
The n=... parameter of numpy.fft.irfft is not reachable when calling GUM_iDFT. Hence, the reconstruction always assumes an original signal of even length. Also workarounds with zero-padding and removal via the GUM_iDFT(..., Nx=...) cannot yield the desired result.
This might be related to #99 . I would suggest to stick to the numpy behavior, in order to simplify transition from existing routines based on numpy/scipy to the uncertainty-enhanced versions in PyDynamic. However, this would probably require some careful adjustments in the uncertainty evaluation.
Currently,
GUM_DFT
andGUM_iDFT
are based onnumpy.fft.rfft
andnumpy.fft.irfft
respectivly.Assume two signals of even and odd length:
As mentioned in the numpy documentation,
numpy.fft.irfft
requires the length of the original signal for a proper reconstruction, otherwise an original signal of even length is assumed. Therefore, to achieve identity of the reconstruction for the above signals, it is necessary to call:The
n=...
parameter ofnumpy.fft.irfft
is not reachable when callingGUM_iDFT
. Hence, the reconstruction always assumes an original signal of even length. Also workarounds with zero-padding and removal via theGUM_iDFT(..., Nx=...)
cannot yield the desired result.This might be related to #99 . I would suggest to stick to the numpy behavior, in order to simplify transition from existing routines based on numpy/scipy to the uncertainty-enhanced versions in PyDynamic. However, this would probably require some careful adjustments in the uncertainty evaluation.