我想用
convolution operation
来做 FFT
。
将
FFT
应用于两个输入张量并使用 element-wise multiplication
生成输出张量。然后,该输出张量经过 IFFT
产生最终输出。
下面的代码是我写的伪代码。
输入张量:
import torch
a = torch.tensor([0, 1, 2, 3])
b = torch.tensor([1, 2])
伪代码:
fft_a = torch.fft.fft(a)
fft_b = torch.fft.fft(b, n=4)
out = fft_a * fft_b
out = torch.fft.ifft(out)
预期输出:
print(out.real)
>>> tensor([2., 5., 8.])
实际输出:
print(out.real)
>>> tensor([6., 1., 4., 7.])
如何使用
convolution operation
来执行 FFT
?
通过翻转一个输入张量,它可以正常工作。
下面的代码通过翻转 b 输入张量来应用
FFT
。
代码:
import torch
a = torch.tensor([0, 1, 2, 3])
b = torch.flip(torch.tensor([1, 2]), [0])
fft_a = torch.fft.fft(a)
fft_b = torch.fft.fft(b, n=4)
out = fft_a * fft_b
out = torch.fft.ifft(out)
print(out.real[1:])
输出:
tensor([2., 5., 8.])