当前位置:网站首页>torch. fft

torch. fft

2022-06-26 08:45:00 will be that man

This is the package of discrete Fourier transform and its related functions . Before use, you must import torch.fft.

torch.fft.fft(input, n=None, dim=-1, norm=None) → Tensor

One dimensional Fourier transform .

Parameters :

  • input (Tensor): Input tensor
  • n (int, optional) : Signal length , If a given , Then the input tensor is either zero-padding To signal length , Or it is clipped to the signal length .
  • dim (int, optional): Do the dimension of one-dimensional Fourier transform .
  • norm (str, optional): Normalization mode .
    • “forward” - normalize by 1/n
    • “backward” - no normalization
    • “ortho” - normalize by 1/sqrt(n) (making the FFT orthonormal)

Example :

>>> import torch.fft
>>> t = torch.arange(4)
>>> t
tensor([0, 1, 2, 3])
>>> torch.fft.fft(t)
tensor([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])
>>> t = tensor([0.+1.j, 2.+3.j, 4.+5.j, 6.+7.j])
>>> torch.fft.fft(t)
tensor([12.+16.j, -8.+0.j, -4.-4.j,  0.-8.j])

torch.fft.ifft(input, n=None, dim=-1, norm=None) → Tensor

One dimensional inverse Fourier transform .

Parameters : Consistent with one-dimensional Fourier transform .

Example :

>>> import torch.fft
>>> t = torch.tensor([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])
>>> torch.fft.ifft(t)
tensor([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j])

torch.fft.fftn(input, s=None, dim=None, norm=None) → Tensor

N Dimensional Fourier transform .

Parameters :

  • input (Tensor): Input tensor
  • s (Tuple[int], optional): Signal size , If a given , Then the dimension to be transformed by the input tensor is either zero-padding To signal size , Or cut to signal size .
  • dim (Tuple[int], optional): do N Dimension of the dimensional Fourier transform .
  • norm (str, optional): Normalization mode .
    • “forward” - normalize by 1/n
    • “backward” - no normalization
    • “ortho” - normalize by 1/sqrt(n) (making the FFT orthonormal).n = prod(s), yes s The product of all elements in .

Example :

>>> import torch.fft
>>> x = torch.rand(10, 10, dtype=torch.complex64)
>>> fftn = torch.fft.fftn(t)

Because the discrete Fourier transform is separable , Therefore, the two-dimensional discrete Fourier transform is equivalent to two one-dimensional discrete Fourier transforms .

>>> two_ffts = torch.fft.fft(torch.fft.fft(x, dim=0), dim=1)
>>> torch.allclose(fftn, two_ffts)

torch.fft.ifftn(input, s=None, dim=None, norm=None) → Tensor

N Inverse dimensional Fourier transform .

Parameters : Consistent with dimensional Fourier transform .

Example :

>>> import torch.fft
>>> x = torch.rand(10, 10, dtype=torch.complex64)
>>> ifftn = torch.fft.ifftn(t)

Because inverse discrete Fourier transform is separable , Therefore, the two-dimensional inverse discrete Fourier transform is equivalent to two one-dimensional inverse discrete Fourier transforms .

>>> two_iffts = torch.fft.ifft(torch.fft.ifft(x, dim=0), dim=1)
>>> torch.allclose(ifftn, two_iffts)

torch.fft.fftshift(input, dim=None) → Tensor

Put the low frequency part of the converted frequency domain image in the middle of the image , Only for easy observation . Apply to N dimension .

Parameters :

  • input (Tensor): Input frequency domain tensor .
  • dim (int, Tuple[int], optional): Do the dimension of sequence exchange .

Example :

>>> f = torch.fft.fftfreq(4)
>>> f
tensor([ 0.0000,  0.2500, -0.5000, -0.2500])
>>> torch.fft.fftshift(f)
tensor([-0.5000, -0.2500,  0.0000,  0.2500])

torch.fft.ifftshift(input, dim=None) → Tensor

fftshift() The inverse transformation of .

Parameters : And fftshift Parameters are consistent .

Example :

>>> f = torch.fft.fftfreq(5)
>>> f
tensor([ 0.0000,  0.2000,  0.4000, -0.4000, -0.2000])
>>> shifted = torch.fft.fftshift(f)
>>> torch.fft.ifftshift(shifted)
tensor([ 0.0000,  0.2000,  0.4000, -0.4000, -0.2000])
原网站

版权声明
本文为[will be that man]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170554582919.html