问题描述
import os
import scipy.io
import scipy.io.wavfile
import numpy as np
import matplotlib.pyplot as plt
dataset_path = os.path.join(os.environ['HOME'],'shared','data','assignment_1')
wavedata = os.path.join(dataset_path,'example.wav')
fs,audio_buffer = scipy.io.wavfile.read(wavedata)
a = np.array(audio_buffer)
frame_size = 2048
start_frame = 2*fs
T = 1/fs # sampling period
t = 2048/fs # seconds of sampling
frame = np.array(a[0:int(fs*t):]) # total points in signal
#because the starting point is 2*fs and the amount of frames is 2048
spectrum = np.fft.fft(a) [start_frame:start_frame+frame_size:]
abs_spec = abs(spectrum) [0:int(frame_size/2):]
plt.plot(abs_spec)
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude")
plt.show()
我需要对.wav文件执行DFT。 但实际上我不确定我在x和y轴上得到了什么。 我需要它
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude")
能不能告诉我我做得对吗?
也有一个问题
abs_spec = abs(spectrum) [0:int(frame_size/2):]
本意是用于消除虚数的。
或者我应该只完成步骤2:
abs_spec = abs(spectrum) [0:frame_size: 2]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)