torch.fft类下面的函数

这篇博客比较简洁给大家一个直观的对序列的傅里叶变换与其逆变换,具体可以参考底部链接

torch.fft.fft&&torch.fft.ifft

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

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

import torch.fft
x=8#x得是2的n次方
t= torch.arange(x)
t
==========================
tensor([0, 1, 2, 3, 4, 5, 6, 7])
==========================
result = torch.fft.fft(t)
result
==========================
tensor([28.+0.0000j, -4.+9.6569j, -4.+4.0000j, -4.+1.6569j, -4.+0.0000j,
        -4.-1.6569j, -4.-4.0000j, -4.-9.6569j])
==========================
result_inverse = torch.fft.ifft(result)
result_inverse
==========================
tensor([0.0000+0.j, 1.0000+0.j, 2.0000+0.j, 3.0000+0.j, 4.0000+0.j, 5.0000+0.j, 6.0000+0.j,7.0000+0.j])
==========================

torch.fft.rfft&&torch.fft.irfft

fft:快速离散傅里叶变换

rfft:因为中心共轭对称,所以将共轭的那一部分去除,减少存储量,其意义都是去除那些共轭对称的值,减小存储,在1.7版本torch.rfft中,有一个warning,表示在新版中,要“one-side ouput”的话用torch.fft.rfft(),要“two-side ouput”的话用torch.fft.fft()。这里的one/two side,跟旧版的onesided参数对应,所以我们要的是新版的torch.fft.fft()

import torch.fft
x=8#x得是2的n次方
t= torch.arange(x)
t
==========================
tensor([0, 1, 2, 3, 4, 5, 6, 7])
==========================
result = torch.fft.rfft(t)
result
==========================
tensor([28.+0.0000j, -4.+9.6569j, -4.+4.0000j, -4.+1.6569j, -4.+0.0000j])
==========================
result_inverse = torch.fft.irfft(result)
result_inverse
==========================
tensor([0., 1., 2., 3., 4., 5., 6., 7.])
==========================

官方参考 TORCH.FFT

 

Reference

torch.fft_will be that man的博客-CSDN博客_torch.fft//总结的不错

torch.fft — PyTorch 1.11.0 documentation//官方文档,细节都在这里了

猜你喜欢

转载自blog.csdn.net/weixin_43332715/article/details/124755174