xdas.fft.irfft#

xdas.fft.irfft(da, n=None, dim={'last': 'signal'}, norm=None, parallel=None)[source]#

Compute the inverse of rfft.

Parameters:
  • da (DataArray) – The data array to process, can be complex.

  • n (int, optional) – Length of the transformed dimension of the output. For n output points, n//2+1 input points are necessary. If the input is longer than this, it is cropped. If it is shorter than this, it is padded with zeros. If n is not given, it is taken to be 2*(m-1) where m is the length of the input along the dimension specified by dim.

  • dim ({str: str}, optional) – A mapping indicating as a key the dimension along which to compute the FFT, and as value the new name of the dimension. Default to {“last”: “time”}.

  • norm ({“backward”, “ortho”, “forward”}, optional) – Normalization mode (see numpy.fft). Default is “backward”. Indicates which direction of the forward/backward pair of transforms is scaled and with what normalization factor.

Returns:

The truncated or zero-padded input, transformed along the dimension indicated by dim, or the last one if dim is not specified. The length of the transformed dimension is n, or, if n is not given, 2*(m-1) where m is the length of the transformed dimension of the input. To get an odd number of output points, n must be specified.

Return type:

DataArray

Notes

To perform a multidimensional Fourier operations, repeat this function on the desired dimensions.

Examples

>>> import xdas as xd
>>> import xdas.fft as xfft
>>> signal = xd.DataArray([0., 1., 0., -1.], coords={"time": [0, 1, 2, 3]})
>>> spectrum = xfft.rfft(signal, dim={"time": "frequency"})
>>> result = xfft.irfft(
...    spectrum,
...    n=signal.sizes["time"],  # ensure correct output if n is odd
...    dim={"frequency": "time"},
... )
>>> result["time"] = signal["time"]  # to match time coordinates
>>> assert np.real(result).equals(signal)