【发布时间】:2017-11-22 12:30:45
【问题描述】:
我试图理解一段代码,在我看来它试图先应用过滤器然后计算 FFT。 我不明白它是怎么做到的。谁能给我解释一下。 代码如下:
# Parameters to create the spectrogram
N = 160000 # No. of frames in .wav file
K = 512
step = 4
wind = 0.5 * (1 - np.cos(np.array(range(K)) * 2 * np.pi / (K - 1))) # 0.5*2*sin(o/2), creation of filter window
ffts = []
def wav_to_floats(file):
s = wave.open(file, 'r')
str_sig = s.readframes(s.getnframes())
y = np.fromstring(str_sig, np.short)
s.close()
return y
for file_index in range(len(label)):
test_flag = label.iloc[file_index]['fold'] # 0 - training data, 1 - test data
fname = label.iloc[file_index]['filename']
#-------------from here i dont understand mainly------------
spectogram = []
s = wav_to_floats(essential_folder+'src_wavs/'+fname+'.wav')
for j in range(int((step*N/K) - step)):
vec = s[j * K/step : (j+step) * K/step] * wind
spectogram.append(abs(fft(vec, K)[:K / 2]))
ffts.append(np.array(spectogram))
【问题讨论】:
标签: python audio signal-processing fft