带幅度和相位的Pytorch逆FFT(ifft)

jxct1oxe  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(263)

为了使用振幅和相位,我使用下面的函数来提取:

  1. def calculate_fft(x):
  2. fft_im = torch.fft.fft(x.clone()) # bx3xhxw
  3. fft_amp = fft_im.real**2 + fft_im.imag**2
  4. fft_amp = torch.sqrt(fft_amp)
  5. fft_pha = torch.atan2(fft_im.imag, fft_im.real)
  6. return fft_amp, fft_pha

修改amppha后,如何使用它们执行逆FFT?

  1. y = fft_amp * torch.sin(fft_pha)

英译汉这不起作用。我数学不好。

5w9g7ksd

5w9g7ksd1#

  1. def inverse_fft(fft_amp, fft_pha):
  2. imag = fft_amp * torch.sin(fft_pha)
  3. real = fft_amp * torch.cos(fft_pha)
  4. fft_y = torch.complex(real, imag)
  5. y = torch.fft.ifft(fft_y)
  6. return y

这可能行得通。

相关问题