Package lib :: Module RMSlib
[frames] | no frames]

Source Code for Module lib.RMSlib

 1  import math 
 2  import numpy 
 3  from gpk_voicing import voice_misc 
 4  from gpk_voicing import power 
 5   
 6   
 7   
 8   
9 -def one_pk_pk(t, data, dt, Pkwdt):
10 """Measure the peak-to-peak amplitude near time t. 11 @param t: the time to measure near (units of seconds) 12 @type t: float (seconds). 13 @param data: the time-series. 14 @type data: numpy.ndarray 15 @param dt: the sampling interval for data 16 @type dt: float (seconds). 17 @param Pkwdt: Half-width of region over which to compute 18 the peak-to-peak amplitude. The low end of the 19 frequency response will be on the order of 1/Pkwdt. 20 @type Pkwdt: float (seconds). 21 @return: scalar peak-to-peak amplitude 22 @rtype: float 23 """ 24 s, e = voice_misc.start_end(t, dt, int(round(Pkwdt/dt)), data.shape[0]) 25 d = data[s:e] 26 return d[ numpy.argmax( d ) ] - d[ numpy.argmin(d) ]
27 28
29 -def compute_intensity(data, dt, DT, DR, HPF, DTSmooth):
30 """Measure the time-series of RMS of a data array data. 31 DT is the sampling interval for the resulting RMS time series.""" 32 if HPF is not None: 33 data = voice_misc.hipass_sym_butterworth(data, HPF*dt) 34 if DR == 'rms': 35 pwr, t0 = power.smooth(numpy.square(data), dt, DT, DTSmooth) 36 rms = numpy.sqrt(pwr) 37 elif DR == 'avd': 38 rms,t0 = power.smooth(numpy.absolute(data), dt, DT, DTSmooth) 39 elif DR == 'pkpk': 40 ns = int(math.floor(data.shape[0]*(dt/DT))) 41 # print 'ns=', dt, data.shape[0], DT, dt*data.shape[0]/DT 42 pkpk = numpy.zeros((ns,)) 43 for t in range(ns): 44 pkpk[t] = one_pk_pk(t*DT, data, dt, math.hypot(DTSmooth, DT)) 45 rms,t0 = power.smooth(pkpk, DT, DT, DTSmooth) 46 else: 47 raise ValueError, 'Bad DR=%s' % DR 48 return (rms,t0)
49