Hi Ptrblck
I want to compute instantaneous frequency (IF) from hilbert transform using pytorch.
Currently, I am using Matlab for this task.
Matlab script:
[x,fs]=audioread('waveform');

for i = 1:length(sinc_filter)
    C(i,:) = conv(x,sinc{i},'same');
    HT(i,:)=(hilbert(C(i,:)));
    instfreq (i,:)= abs(fs/(2*pi)*diff(unwrap(angle(HT(i,:)))));
end


I want to do the same thing in pytorch.
I didn’t find hilbert and unwrape function in pytorch.
I tried using numpy but that’s taking lot of time for computing instantaneous frequency for each mini-batch.
python script using numpy:
#no. of sinc filters=21
#filter_length=128
#mini-batch size=8
#self.filters size is [1,no. of sinc filters, filter_length]
# Filter is sinc filters with size [batch_size, no. of sinc filter, audio samples(64000 samples)]. 

Filter=F.conv1d(waveforms, self.filters, stride=self.stride,
                        padding=self.padding, dilation=self.dilation,
                         bias=None, groups=1) 

self.Filter=Filter

fs=16000

FILTER_1=self.Filter.cpu().detach().numpy()  

inst_freq=np.zeros((self.Filter.shape[0],self.Filter.shape[1],Filter.shape[2]-1))  # intialized inst_freq matrix

# 1st for loop to compute IF for each filter and 2nd for loop is for each audio wave in mini-batch.
# j range from 0 to 20.
# i range from 0 to 7.


for j in range(self.Filter.shape[1]):
    for i in range(self.Filter.shape[0]):
        z= hilbert(FILTER_1[i,j,:])
        inst_phase = np.unwrap(np.angle(z))
        inst_freq[i,j,:] = np.diff(inst_phase)/(2*np.pi)*fs 
                
  
Main_filt=torch.from_numpy(inst_freq).type(torch.float).to(self.device)


But its taking lot of time for IF computation.
Is there any way to do this things in pytorch.
Please let me know what is the best option to do this operations for IF computation in pytorch.
your suggestions would be really useful for me.
Thanks in advance.