Rate this Page

torch.fft.hfft#

torch.fft.hfft(input,n=None,dim=-1,norm=None,*,out=None)Tensor#

Computes the one dimensional discrete Fourier transform of a Hermitiansymmetricinput signal.

Note

hfft()/ihfft() are analogous torfft()/irfft(). The real FFT expectsa real signal in the time-domain and gives a Hermitian symmetry in thefrequency-domain. The Hermitian FFT is the opposite; Hermitian symmetric inthe time-domain and real-valued in the frequency-domain. For this reason,special care needs to be taken with the length argumentn, in thesame way as withirfft().

Note

Because the signal is Hermitian in the time-domain, the result will bereal in the frequency domain. Note that some input frequencies must bereal-valued to satisfy the Hermitian property. In these cases the imaginarycomponent will be ignored. For example, any imaginary component ininput[0] would result in one or more complex frequency terms whichcannot be represented in a real output and so will always be ignored.

Note

The correct interpretation of the Hermitian input depends on the length ofthe original data, as given byn. This is because each input shapecould correspond to either an odd or even length signal. By default, thesignal is assumed to be even length and odd signals will not round-tripproperly. So, it is recommended to always pass the signal lengthn.

Note

Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.However it only supports powers of 2 signal length in every transformed dimension.With default arguments, size of the transformed dimension should be (2^n + 1) as argumentn defaults to even output size = 2 * (transformed_dim_size - 1)

Parameters
  • input (Tensor) – the input tensor representing a half-Hermitian signal

  • n (int,optional) – Output signal length. This determines the length of thereal output. If given, the input will either be zero-padded or trimmed to thislength before computing the Hermitian FFT.Defaults to even output:n=2*(input.size(dim)-1).

  • dim (int,optional) – The dimension along which to take the one dimensional Hermitian FFT.

  • norm (str,optional) –

    Normalization mode. For the forward transform(hfft()), these correspond to:

    • "forward" - normalize by1/n

    • "backward" - no normalization

    • "ortho" - normalize by1/sqrt(n) (making the Hermitian FFT orthonormal)

    Calling the backward transform (ihfft()) with the samenormalization mode will apply an overall normalization of1/n betweenthe two transforms. This is required to makeihfft()the exact inverse.

    Default is"backward" (no normalization).

Keyword Arguments

out (Tensor,optional) – the output tensor.

Example

Taking a real-valued frequency signal and bringing it into the time domaingives Hermitian symmetric output:

>>>t=torch.linspace(0,1,5)>>>ttensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])>>>T=torch.fft.ifft(t)>>>Ttensor([ 0.5000-0.0000j, -0.1250-0.1720j, -0.1250-0.0406j, -0.1250+0.0406j,        -0.1250+0.1720j])

Note thatT[1]==T[-1].conj() andT[2]==T[-2].conj() isredundant. We can thus compute the forward transform without consideringnegative frequencies:

>>>torch.fft.hfft(T[:3],n=5)tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])

Like withirfft(), the output length must be given in orderto recover an even length output:

>>>torch.fft.hfft(T[:3])tensor([0.1250, 0.2809, 0.6250, 0.9691])