jax.numpy.fft.hfft
Contents
jax.numpy.fft.hfft#
- jax.numpy.fft.hfft(a,n=None,axis=-1,norm=None)[source]#
Compute a 1-D FFT of an array whose spectrum has Hermitian symmetry.
JAX implementation of
numpy.fft.hfft().- Parameters:
a (ArrayLike) – input array.
n (int |None) – optional, int. Specifies the dimension of the result along
axis. Ifnot specified,n=2*(m-1), wheremis the dimension ofaalongaxis.axis (int) – optional, int, default=-1. Specifies the axis along which the transformis computed. If not specified, the transform is computed along axis -1.
norm (str |None) – optional, string. The normalization mode. “backward”, “ortho” and “forward”are supported. Default is “backward”.
- Returns:
A real-valued array containing the one-dimensional discrete Fourier transformof
aby exploiting its inherent Hermitian-symmetry, having a dimension ofnalongaxis.- Return type:
See also
jax.numpy.fft.ihfft(): Computes a one-dimensional inverse FFT of anarray whose spectrum has Hermitian symmetry.jax.numpy.fft.fft(): Computes a one-dimensional discrete Fouriertransform.jax.numpy.fft.rfft(): Computes a one-dimensional discrete Fouriertransform of a real-valued input.
Examples
>>>x=jnp.array([[1,3,5,7],...[2,4,6,8]])>>>jnp.fft.hfft(x)Array([[24., -8., 0., -2., 0., -8.], [30., -8., 0., -2., 0., -8.]], dtype=float32)
This value is equal to the real component of the discrete Fourier transformof the following array
x1computed usingjnp.fft.fft.>>>x1=jnp.array([[1,3,5,7,5,3],...[2,4,6,8,6,4]])>>>jnp.fft.fft(x1)Array([[24.+0.j, -8.+0.j, 0.+0.j, -2.+0.j, 0.+0.j, -8.+0.j], [30.+0.j, -8.+0.j, 0.+0.j, -2.+0.j, 0.+0.j, -8.+0.j]], dtype=complex64)>>>jnp.allclose(jnp.fft.hfft(x),jnp.fft.fft(x1))Array(True, dtype=bool)
To obtain an odd-length output from
jnp.fft.hfft,nmust be specifiedwith an odd value, as the default behavior produces an even-length resultalong the specifiedaxis.>>>withjnp.printoptions(precision=2,suppress=True):...print(jnp.fft.hfft(x,n=5))[[17. -5.24 -0.76 -0.76 -5.24] [22. -5.24 -0.76 -0.76 -5.24]]
When
n=3andaxis=0, dimension of the transform alongaxis0willbe3and dimension along other axes will be same as that of input.>>>jnp.fft.hfft(x,n=3,axis=0)Array([[ 5., 11., 17., 23.], [-1., -1., -1., -1.], [-1., -1., -1., -1.]], dtype=float32)
xcan be reconstructed (but of complex datatype) usingjnp.fft.ihfftfrom the result ofjnp.fft.hfft, only whennis specified as2*(m-1)ifm is even or2*m-1ifmis odd, wheremis the dimension ofinput alongaxis.>>>jnp.fft.ihfft(jnp.fft.hfft(x,2*(x.shape[-1]-1)))Array([[1.+0.j, 3.+0.j, 5.+0.j, 7.+0.j], [2.+0.j, 4.+0.j, 6.+0.j, 8.+0.j]], dtype=complex64)>>>jnp.allclose(x,jnp.fft.ihfft(jnp.fft.hfft(x,2*(x.shape[-1]-1))))Array(True, dtype=bool)
For complex-valued inputs:
>>>x2=jnp.array([[1+2j,3-4j,5+6j],...[2-3j,4+5j,6-7j]])>>>jnp.fft.hfft(x2)Array([[ 12., -12., 0., 4.], [ 16., 6., 0., -14.]], dtype=float32)
