picadae calibration programs
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

elbow.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import sys,os
  2. import numpy as np
  3. import common
  4. import rms_analysis
  5. def fit_points_to_reference( usL, dbL, usRefL, dbRefL ):
  6. dbV = None
  7. yyL = [ (db,dbRefL[ usRefL.index(us)]) for i,(us,db) in enumerate(zip(usL,dbL)) if us in usRefL ]
  8. if len(yyL) < 10:
  9. print("NO FIT")
  10. else:
  11. y0L,yrL = zip(*yyL)
  12. yN = len(y0L)
  13. A = np.vstack([np.ones(yN),y0L]).T
  14. c,m = np.linalg.lstsq(A,yrL,rcond=None)[0]
  15. dbV = (np.array(dbL) * m) + c
  16. return dbV
  17. def find_elbow( usL, dbL, pointsPerLine=10 ):
  18. ppl_2 = int(pointsPerLine/2)
  19. dL = []
  20. i = pointsPerLine
  21. # for each consecutive set of 'pointsPerLine' points in usL and dbL
  22. while i < len(usL):
  23. # find the x,y coordinates of the first 'ppl_2' coordinates
  24. x0L = np.array([ (us,1.0) for us in usL[i-pointsPerLine:i-ppl_2] ])
  25. y0L = np.array(usL[i-pointsPerLine:i-ppl_2])
  26. # find the x,y coordinates of the second 'ppl_2' coordinates
  27. x1L = np.array([ (us,1.0) for us in usL[i-ppl_2:i]])
  28. y1L = np.array(dbL[i-ppl_2:i])
  29. m0,c0 = np.linalg.lstsq(x0L,y0L,rcond=None)[0] # fit a line through the first set of points
  30. m1,c1 = np.linalg.lstsq(x1L,y1L,rcond=None)[0] # fit a line through the second set of points
  31. # store the angle between the two lines
  32. dL.append(m1-m0)
  33. i += 1
  34. # find the max angle
  35. i = np.argmax( dL )
  36. # return the x,y coordinate of the first data point of the second line
  37. return (usL[i+ppl_2],dbL[i+ppl_2])
  38. def find_elbow_main( cfg, inDir, midi_pitch, takeId ):
  39. inDir = os.path.join(inDir,str(pitch),str(takeId))
  40. analysisArgsD = cfg.analysisArgs['rmsAnalysArgs']
  41. r = rms_analysis_main( inDir, int(midi_pitch), **analysisD )
  42. usL = r.pkUsL
  43. dbL = r.pkDbL
  44. return find_elbow(r.pkUsL,r.pkDbL)
  45. if __name__ == "__main__":
  46. inDir = sys.argv[1]
  47. cfgFn = sys.argv[2]
  48. pitch = sys.argv[3]
  49. cfg = common.parse_yaml_cfg(cfgFn)
  50. find_elbow( cfg, inDir, pitch, 0 )