-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsignal_utils.py
More file actions
31 lines (25 loc) · 772 Bytes
/
Copy pathsignal_utils.py
File metadata and controls
31 lines (25 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import torch
import torch.fft
def fft2(x):
assert len(x.shape) == 4
x = torch.fft.fft2(x, norm='ortho')
return x
def ifft2(x):
assert len(x.shape) == 4
x = torch.fft.ifft2(x, norm='ortho')
return x
def fftshift2(x):
assert len(x.shape) == 4
x = torch.roll(x, (x.shape[-2]//2, x.shape[-1]//2), dims=(-2, -1))
return x
def ifftshift2(x):
assert len(x.shape) == 4
x = torch.roll(x, ((x.shape[-2]+1)//2, (x.shape[-1]+1)//2), dims=(-2, -1))
return x
def rss(x):
assert len(x.shape) == 4
return torch.linalg.vector_norm(x, ord=2, dim=1, keepdim=True)
#if torch.is_complex(x):
# return (x.real**2 + x.imag**2).sum(dim=1, keepdim=True).sqrt()
#else:
# return (x**2).sum(dim=1, keepdim=True)**0.5