SciPy - ihfftn() Function



SciPy's function ihfftn() is a n-dimensional inverse Hermitian Fast Fourier Transform of real-valued frequency-domain data reconstructed from the original spatial domain signal. This is an extension to both ihfft and ihfft2 with the scope of handling multi-dimensional arrays, which also reconstruct the data efficiently and retain the input as real.

ihfftn() is widely applied in multidimensional signal processing, picture reconstruction, and scientific computing. It finds its best application in recreating spatial signals from frequency-domain data in volumetric scanning, 3D image filtering, and simulations.

This method allows exact data manipulation in several dimensions while preserving Hermitian symmetry.

Syntax

The syntax for the SciPy ihfftn() method is as follows −

.ihfftn(x, s=None, axes=None, norm=None, overwrite_x=False, workers=None, *, plan=None)

Parameters

This method accepts the following parameters −

  • x (array_like) − Input Hermitian symmetric frequency-domain data.

  • s (sequence of ints, optional) − Shape of the real output; truncates or zero-pads input to match.

  • axes (sequence of ints, optional) − Axes along which the inverse FFT is computed. Defaults to all axes.

  • norm ({"backward", "ortho", "forward"}, optional) − Normalization mode: "backward" (default), "ortho" for energy preservation, or "forward".

  • overwrite_x (bool, optional) − Allows overwriting x to save memory. Default is False.

  • workers (int, optional) − Number of parallel threads for computation. Default is single-threaded.

  • plan (optional) − For experimental precomputed FFT plans. Rarely used.

Return Value

out ndarray − Real-valued n-dimensional array reconstructed from the input Hermitian symmetric frequency-domain data.

Example 1

The following code demonstrates how to use ihfftn(), a real-valued 3D array is transformed into the Hermitian symmetric frequency domain using hfftn and then reconstructed by ihfftn into the original spatial data, so that a round-trip transformation is accomplished.

import numpy as np
from scipy.fft import hfftn, ihfftn

# Create real-valued data and compute Hermitian symmetric frequency data
real_data = np.random.rand(2, 2, 2)
freq_data = hfftn(real_data)

# Perform the inverse Hermitian FFT
spatial_data = ihfftn(freq_data)

print("Original Real Data:\n", real_data)
print("Reconstructed Spatial Data:\n", spatial_data)

When we run above program, it produces following result

Original Real Data:
 [[[0.15 0.05]
  [0.69 0.54]]

 [[0.93 0.64]
  [0.52 0.51]]]
Reconstructed Spatial Data:
 [[[0.15+0.j 0.05+0.j]
  [0.69+0.j 0.54+0.j]]

 [[0.93+0.j 0.64+0.j]
  [0.52+0.j 0.51+0.j]]]

Example 2

The axis parameter in ihfftn restricts the transformation to some dimensions, which will then have an impact on reconstruction, and norm="ortho" scales the output to conserve energy and induce amplitude variations. All of these settings affect the spatial domain translation of the data from the frequency domain.

This code illustrates the implementation of ihfftn for the reconstruction of spatial data from the Hermitian symmetric frequency-domain input, including default behavior with specific axis transformations using a tuple axes=(2, 0) and using orthogonal normalization norm="ortho" to keep the energy.

import numpy as np
from scipy.fft import ihfftn

x = np.ones((2, 2, 2))

# Perform inverse FFT with default settings
default_axes_output = ihfftn(x)

# Perform inverse FFT along specific axes
custom_axes_output = ihfftn(x, axes=(2, 0))

# Perform inverse FFT with orthogonal normalization
norm_output = ihfftn(x, norm="ortho")

print("Default Axes Output:\n", default_axes_output)
print("Custom Axes Output (axes=(2, 0)):\n", custom_axes_output)
print("Orthogonal Normalization Output:\n", norm_output)

Following is an output of the above code −

Default Axes Output:
 [[[1.+0.j 0.+0.j]
  [0.+0.j 0.+0.j]]

 [[0.+0.j 0.+0.j]
  [0.+0.j 0.+0.j]]]
Custom Axes Output (axes=(2, 0)):
 [[[1.+0.j 0.+0.j]
  [1.+0.j 0.+0.j]]

 [[0.+0.j 0.+0.j]
  [0.+0.j 0.+0.j]]]
Orthogonal Normalization Output:
 [[[2.83+0.j 0.  +0.j]
  [0.  +0.j 0.  +0.j]]

 [[0.  +0.j 0.  +0.j]
  [0.  +0.j 0.  +0.j]]]
scipy_discrete_fourier_transform.htm
Advertisements