While trying to preprocess the signal, it shows this error TypeError: torch.Size() takes an iterable of 'int' (item 0 is 'tuple')
. However, I’m using PyTorch for audio preprocessing, and want to apply the High-Pass Filter
over the entire load signals. The below code is my current try with PyTorch. Hence, how can I use the High-Pass filter
with PyTorch? my signals shape is torch.Size([30, 100, 100])
, each signal shape is torch.Size([1, 100, 100])
. Here is my code:
import torch
from load_data import AudioRead
from scipy import signal
SAMPLE_RATE = 48000
CARRIER_FREQUENCY = 18000
BOTTOM_FREQUENCY = 19000
TOP_FREQUENCY = 17000
CUT_OFF = 5
BANDWITH = BOTTOM_FREQUENCY - TOP_FREQUENCY
def high_pass_filter(signal_data, cut_off, sample_rate, carrier_frequency, bandwith):
"""
Based DSP for audio signal processing
:return:
:rtype:
"""
[b, a] = torch.FloatTensor(signal.butter(cut_off, (carrier_frequency - bandwith/2) / (sample_rate/2), 'high'))
signal_size = torch.Size(signal_data)
for ii in range(1, len(signal_size)):
if signal_data != 0:
signal_data[ii] = filter([b, a, signal_data[ii, :]])
else:
raise ValueError("Signals are not iterable. Null !!!!")
return b, a
if __name__ == '__main__':
path_dir = r"D:\ACG-Data\acg"
ANNOTATION_FILE = r"D:\ACG-Data\acg\training_rate.csv"
TRANSFORMATION = None
SAMPLE_RATE = 48000
REAL_SAMPLE_RATE = 48000
if torch.cuda.is_available():
DEVICE = 'cuda'
else:
DEVICE = 'cpu'
data_load = AudioRead(ANNOTATION_FILE, path_dir,
TRANSFORMATION, SAMPLE_RATE,
REAL_SAMPLE_RATE, DEVICE)
high_pass_filter(data_load, CUT_OFF, SAMPLE_RATE, CARRIER_FREQUENCY, BANDWITH)
Error: