Hello, I am new to signal processing and I wanted to perform gabor wavelet transform on DNA sequence to detect 3 base periodicity in coding regions using python and pytorch to perform the convolution operation and here is the code :
def gabor_transform(x,window, omega0, sigma,t1):
total = torch.zeros(x.shape[1], dtype=torch.float,requires_grad=False)
theta = math.pi /3
for i in range(x.shape[0]) :
if i == 0:
d = math.cos(theta) + 1j * math.sin(theta)
elif i == 1:
d = -math.cos(theta) - 1j * math.sin(theta)
elif i == 2:
d = -math.cos(theta) + 1j * math.sin(theta)
elif i == 3:
d = math.cos(theta) - 1j * math.sin(theta)
x1 = x[i,:]
t = torch.arange(-window / 2, window / 2,requires_grad=False)
g = torch.exp(-(t**2) / (2 * sigma**2)) * torch.exp(1j * omega0 * t)
X = torch.fft.fft(x1.to(dtype=torch.complex64)).unsqueeze(0).unsqueeze(0)
G = torch.fft.fft(g.to(dtype=torch.complex64)).unsqueeze(0).unsqueeze(0)
Conv = torch.nn.Conv1d(1, 1, window, stride=1, padding=int(window//2), bias=False)
G = torch.nn.Parameter(G,requires_grad=False)
Conv.weight = G
C = Conv(X).view(-1)
C = torch.abs(C)**2
total += C
return total
with x
being one hot encoded dna sequence. I wanted those who has experience with signal processing if I am doing it right