Added fit-curve to vib_analyze's pylab output.
authorW. Trevor King <wking@drexel.edu>
Wed, 26 Nov 2008 20:46:28 +0000 (15:46 -0500)
committerW. Trevor King <wking@drexel.edu>
Wed, 26 Nov 2008 20:46:28 +0000 (15:46 -0500)
Gave up on the gnuplot output for now.

calibcant/vib_analyze.py

index f7d8033e2678f45f146f2c5fb3ecca3d96ad2891..33a829b70bf4b559fec896c1b920710aed1e6dcf 100755 (executable)
@@ -95,7 +95,8 @@ def vib_analyze(deflection_bits, freq, minFreq=500, maxFreq=7000,
         print "Fitted f(x) = C / ((A**2-x**2)**2 + (x*B)**2) with"
         print "A = %g, \t B = %g, \t C = %g" % (A, B, C)
 
-    vib_plot(deflection_bits, freq_axis, power, A, B, C, plotVerbose=plotVerbose)
+    vib_plot(deflection_bits, freq_axis, power, A, B, C,
+             plotVerbose=plotVerbose)
 
     # Our A is in uV**2, so convert back to Volts**2
     return lorentzian_area(A,B,C) * 1e-12
@@ -265,7 +266,7 @@ def vib_plot(deflection_bits, freq_axis, power, A, B, C,
         n, bins, patches = \
             common._pylab.hist(deflection_bits, bins=30,
                                normed=1, align='center')
-        gaus = numpy.zeros((len(bins),))
+        gaus = numpy.zeros((len(bins),), dtype=numpy.float)
         mean = deflection_bits.mean()
         std = deflection_bits.std()
         pi = numpy.pi
@@ -279,8 +280,13 @@ def vib_plot(deflection_bits, freq_axis, power, A, B, C,
         # plot FFTed data
         common._pylab.subplot(313)
         common._pylab.semilogy(freq_axis, power, 'r.-')
+        fitdata = C / ((A**2-freq_axis**2)**2 + (B*freq_axis)**2)
+        common._pylab.hold(True)
+        common._pylab.plot(freq_axis, fitdata, 'b-');
+        common._pylab.hold(False)
+        
         common._flush_plot()
-    if (plotVerbose or config.GNUPLOT_VERBOSE):
+    if (plotVerbose or config.GNUPLOT_VERBOSE): # TODO: cleanup and test
         # write all the ft data now
         fd = file(datafilename, 'w')
         for i in range(len(freq_axis)) :