y, sinefit, label= r'$A\cos (\omega_{sine_1}y) \frac{N-y}{N}$, $\omega_{sine_1}$=%.3f' % (omega / dx)) plt.plot( y, sinefit2, label= r'$A\cos (\omega_{sine_2}y) \frac{N-y}{N}$, $\omega_{sine_2}$=%.3f' % (omega2 / dx)) start_j = 1 for n in range(1, 4): start = time.time() y_max = acf_argmax(f, start_j) end = time.time() if not ii and n == 1: print 'ACF 1stmax computation time: %.3fus' % (1e6 * (end - start)) #sys.exit () start_j = y_max + 1 est_period = dx * y_max / n plt.axvline(y_max, label='$%s\cdot2\pi/(\Delta x\cdot y_{max}^{(%s)})$=%.3f' % (n, n, 2 * pi / est_period), color='k') plt.legend() plt.xlabel('y') plt.ylabel('acf') plt.title('Autocorrelation functions')
from numpy import * from iocbio.ops.autocorrelation import acf, acf_argmax, acf_sinefit # Define a signal: dx = 0.05 x = arange(0,2*pi,dx) N = len(x) f = 7*sin(5*x)+6*sin(9*x) # f is shown in the upper right plot below # Calculate autocorrelation function: y = arange(0,N,0.1) af = acf (f, y, method='linear') # af is shown in the lower right plot below # Find the first maximum of the autocorrelation function: y_max1 = acf_argmax(f, method='linear') # The first maximum gives period estimate for f print 'period=',dx*y_max1 print 'frequency=',2*pi/(y_max1*dx) # Find the second maximum of the autocorrelation function: y_max2 = acf_argmax(f, start_j=y_max1+1, method='linear') print y_max1, y_max2 # Find sine-fit of the autocorrelation function: omega = acf_sinefit(f, method='linear') # The parameter omega in A*cos (omega*y)*(N-y)/N gives # another period estimate for f: print 'period=',2*pi/(omega/dx) print 'frequency=', omega/dx
plt.plot(x, (a/N)**0.5 *sin(omega/dx*x), label='$f(x)=\sqrt{A/N}\sin(\omega_{sine_1}x)$') plt.plot(x, (a/N)**0.5 *sin(omega2/dx*x), label='$f(x)=\sqrt{A/N}\sin(\omega_{sine_2}x)$') plt.legend () plt.xlabel ('x') plt.ylabel ('f(x)') plt.title ('Test functions') plt.subplot (sp2) plt.plot(y, acf_data, label='ACF(f(x))') plt.plot(y, sinefit, label=r'$A\cos (\omega_{sine_1}y) \frac{N-y}{N}$, $\omega_{sine_1}$=%.3f' % (omega/dx)) plt.plot(y, sinefit2, label=r'$A\cos (\omega_{sine_2}y) \frac{N-y}{N}$, $\omega_{sine_2}$=%.3f' % (omega2/dx)) start_j = 1 for n in range(1,4): start = time.time() y_max = acf_argmax(f, start_j) end = time.time() if not ii and n==1: print 'ACF 1stmax computation time: %.3fus' % (1e6*(end-start)) #sys.exit () start_j = y_max + 1 est_period = dx * y_max/n plt.axvline(y_max, label='$%s\cdot2\pi/(\Delta x\cdot y_{max}^{(%s)})$=%.3f' % (n, n, 2*pi/est_period), color='k') plt.legend () plt.xlabel('y') plt.ylabel ('acf') plt.title ('Autocorrelation functions') plt.subplot (sp3)
from numpy import * from iocbio.ops.autocorrelation import acf, acf_argmax, acf_sinefit # Define a signal: dx = 0.05 x = arange(0, 2 * pi, dx) N = len(x) f = 7 * sin(5 * x) + 6 * sin(9 * x) # f is shown in the upper right plot below # Calculate autocorrelation function: y = arange(0, N, 0.1) af = acf(f, y, method='linear') # af is shown in the lower right plot below # Find the first maximum of the autocorrelation function: y_max1 = acf_argmax(f, method='linear') # The first maximum gives period estimate for f print 'period=', dx * y_max1 print 'frequency=', 2 * pi / (y_max1 * dx) # Find the second maximum of the autocorrelation function: y_max2 = acf_argmax(f, start_j=y_max1 + 1, method='linear') print y_max1, y_max2 # Find sine-fit of the autocorrelation function: omega = acf_sinefit(f, method='linear') # The parameter omega in A*cos (omega*y)*(N-y)/N gives # another period estimate for f: print 'period=', 2 * pi / (omega / dx) print 'frequency=', omega / dx