【发布时间】:2015-09-02 13:55:23
【问题描述】:
你好,我是 python 的新手,也是声音信号分析的新手。我正在尝试获取出生歌曲(斑胸草雀)的信封。它的信号波动非常快,我尝试了不同的方法。例如,我尝试根据我发现的其他示例绘制信号并使用以下代码获取包络(我在代码中添加了 cmets 以理解它):
#Import the libraries
from pylab import *
import numpy
import scipy.signal.signaltools as sigtool
import scipy, pylab
from scipy.io import wavfile
import wave, struct
import scipy.signal as signal
#Open the txt file and read the wave file (also save it as txt file)
f_out = open('mike_1_44100_.txt', 'w')
w = scipy.io.wavfile.read("mike_1_44100_.wav") #here your sound file
a=w[1]
f_out.write('#time #z' + '\n')
#I print to check
print 'vector w'
print w[0],w[1]
print w
i=w[1].size
p=numpy.arange(i)*0.0000226 #to properly define the time signal with the sample rate
print 'vector p:'
print p
x=numpy.dstack([p,a])
print 'vector x:'
print x[0]
#saving file
numpy.savetxt('mike_1_44100_.txt',x[0])
f_out.close()
print 'i:'
print i
# num is the number of samples in the resampled signal.
num= np.ceil(float(i*0.0000226)/0.0015)
print num
y_resample, x_resample = scipy.signal.resample(numpy.abs(a),num, p,axis=0, window=('gaussian',150))
#y_resample, x_resample = scipy.signal.resample(numpy.abs(a), num, p,axis=-1, window=0)
#Aplaying a filter
W1=float(5000)/(float(44100)/2) #the frequency for the cut over the sample frequency
(b, a1) = signal.butter(4, W1, btype='lowpass')
aaa=a
slp =1* signal.filtfilt(b, a1, aaa)
#Taking the abs value of the signal the resample and finaly aplying the hilbert transform
y_resample2 =numpy.sqrt(numpy.abs(np.imag(sigtool.hilbert(slp, axis=-1)))**2+numpy.abs(np.real(sigtool.hilbert(slp, axis=-1)))**2)
print 'x sampled'
#print x_resample
print 'y sampled'
#print y_resample
xx=x_resample #[0]
yy=y_resample #[1]
#ploting with some style
plot(p,a,label='Time Signal') #to plot amplitud vs time
#plot(p,numpy.abs(a),label='Time signal')
plot(xx,yy,label='Resampled time signal Fourier technique Gauss window 1.5 ms ', linewidth=3)
#plot(ww,label='Window', linewidth=3)
#plot(p,y_resample2,label='Hilbert transformed sime signal', linewidth=3)
grid(True)
pylab.xlabel("time [s]")
pylab.ylabel("Amplitde")
legend()
show()
这里我尝试了两件事,第一是使用 scipy 的 resample 函数来获取包络,但是我对信号幅度有一些我不理解的问题(我上传了使用傅里叶技术获得的图像,但是系统不允许我):
第二种是使用希尔伯特变换来获取信封(现在我再次使用希尔伯特变换上传了图像,系统不允许我)运行我的代码并获得这两个图像是可能的。但是我把这个链接放在http://ceciliajarne.web.unq.edu.ar/?page_id=92&preview=true
现在“信封”又失败了。正如我在某些示例中看到的那样,我尝试对信号进行滤波,但是我的信号被衰减并且我无法获得包络。 谁能帮助我的代码或更好的想法来获取信封?可以使用任何鸟歌作为示例(我可以给你我的),但我需要看看会发生什么复杂的声音不是简单的信号,因为它非常不同(简单的声音两种技术都可以)。
我还尝试修改我在以下位置找到的代码:http://nipy.org/nitime/examples/mtm_baseband_power.html
但我无法为我的信号获得正确的参数,而且我不了解调制部分。我已经问过代码开发人员了,一直在等待答案。
【问题讨论】:
标签: python audio scipy signal-processing