本文简要介绍python语言中 torch.fft.fftshift 的用法。
- 用法:- torch.fft.fftshift(input, dim=None) → Tensor
- 重新排序由 - fftn()提供的 n 维 FFT 数据,使其首先具有负频率项。- 这将执行 n 维数据的周期性移位,以便将原点 - (0, ..., 0)移动到张量的中心。具体来说,到每个选定维度中的- input.shape[dim] // 2。- 注意 - 按照惯例,FFT 首先返回正频率项,然后按相反顺序返回负频率项,因此 Python 中所有 的 - f[-i]给出负频率项。- fftshift()将所有频率重新排列为从负到正的升序,zero-frequency 项位于中心。- 注意 - 对于偶数长度, - f[n/2]处的奈奎斯特频率可以被视为负或正。- fftshift()始终将奈奎斯特项放在 0 索引处。这与- fftfreq()使用的约定相同。- 示例 - >>> 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])- 另请注意, - f[2]处的奈奎斯特频率项已移至张量的开头。- 这也适用于多维变换: - >>> x = torch.fft.fftfreq(5, d=1/5) + 0.1 * torch.fft.fftfreq(5, d=1/5).unsqueeze(1) >>> x tensor([[ 0.0000, 1.0000, 2.0000, -2.0000, -1.0000], [ 0.1000, 1.1000, 2.1000, -1.9000, -0.9000], [ 0.2000, 1.2000, 2.2000, -1.8000, -0.8000], [-0.2000, 0.8000, 1.8000, -2.2000, -1.2000], [-0.1000, 0.9000, 1.9000, -2.1000, -1.1000]])- >>> torch.fft.fftshift(x) tensor([[-2.2000, -1.2000, -0.2000, 0.8000, 1.8000], [-2.1000, -1.1000, -0.1000, 0.9000, 1.9000], [-2.0000, -1.0000, 0.0000, 1.0000, 2.0000], [-1.9000, -0.9000, 0.1000, 1.1000, 2.1000], [-1.8000, -0.8000, 0.2000, 1.2000, 2.2000]])- fftshift()对于空间数据也很有用。如果我们的数据是在中心网格 (- [-(N//2), (N-1)//2]) 上定义的,那么我们可以通过首先应用- ifftshift()来使用在非中心网格 (- [0, N)) 上定义的标准 FFT。- >>> x_centered = torch.arange(-5, 5) >>> x_uncentered = torch.fft.ifftshift(x_centered) >>> fft_uncentered = torch.fft.fft(x_uncentered)- 类似地,我们可以通过应用 - fftshift()将频域分量转换为居中约定。- >>> fft_centered = torch.fft.fftshift(fft_uncentered)- 从中心傅立叶空间回到中心空间数据的逆变换可以通过以相反的顺序应用反向移位来执行: - >>> x_centered_2 = torch.fft.fftshift(torch.fft.ifft(torch.fft.ifftshift(fft_centered))) >>> torch.testing.assert_close(x_centered.to(torch.complex64), x_centered_2, check_stride=False)
参数:
相关用法
- Python PyTorch fft2用法及代码示例
- Python PyTorch fftn用法及代码示例
- Python PyTorch fftfreq用法及代码示例
- Python PyTorch fft用法及代码示例
- Python PyTorch frexp用法及代码示例
- Python PyTorch flip用法及代码示例
- Python PyTorch frombuffer用法及代码示例
- Python PyTorch float_power用法及代码示例
- Python PyTorch floor_divide用法及代码示例
- Python PyTorch fractional_max_pool3d用法及代码示例
- Python PyTorch frac用法及代码示例
- Python PyTorch freeze用法及代码示例
- Python PyTorch fp16_compress_hook用法及代码示例
- Python PyTorch fake_quantize_per_channel_affine用法及代码示例
- Python PyTorch flipud用法及代码示例
- Python PyTorch fliplr用法及代码示例
- Python PyTorch fp16_compress_wrapper用法及代码示例
- Python PyTorch fractional_max_pool2d用法及代码示例
- Python PyTorch from_numpy用法及代码示例
- Python PyTorch filter_wikipedia_xml用法及代码示例
- Python PyTorch fuse_modules用法及代码示例
- Python PyTorch fasterrcnn_mobilenet_v3_large_320_fpn用法及代码示例
- Python PyTorch fmax用法及代码示例
- Python PyTorch fork用法及代码示例
- Python PyTorch fmin用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torch.fft.fftshift。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
