123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- import numpy as np
- import matplotlib.pyplot as plt
-
- from akvo.tressel.decay import *
- from scipy import signal
-
- def quadrature(T, vL, wL, dt, xn, DT, t):
-
-
-
- irsamp = int(T) * int( (1./vL) / dt)
- iisamp = int( ((1./vL)/ dt) * ( .5*np.pi / (2.*np.pi) ) )
-
-
- dsamp = int( DT / dt)
-
- iisamp += dsamp
-
-
-
- xr = xn[dsamp::irsamp]
- xi = xn[iisamp::irsamp]
- phase = np.angle( xr + 1j*xi )
- abse = np.abs( xr + 1j*xi )
-
-
-
-
-
-
-
- ht = signal.hilbert(xn)
- he = np.abs(ht)
- hp = ((np.angle(ht[dsamp::irsamp])))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- FS = 1./dt
- FC = 10.05/(0.5*FS)
- N = 11
- a = [1]
- b = signal.firwin(N, cutoff=FC, window='hamming')
-
-
-
-
- dw = 0
- Q = signal.filtfilt(b, a, xn*2*np.cos((wL+dw)*t))
- I = signal.filtfilt(b, a, xn*2*np.sin((wL+dw)*t))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return Q[N:-N], I[N:-N], t[N:-N]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- def RotateAmplitude(X, Y, zeta, df, t):
- V = X + 1j*Y
- return np.abs(V) * np.exp( 1j * ( np.angle(V) - zeta - 2.*np.pi*df*t ) )
-
-
-
-
-
- def gateIntegrate(T2D, T2T, gpd, sigma, stackEfficiency=2.):
- """ Gate integrate the signal to gpd, gates per decade
- T2D = the time series to gate integrate, complex
- T2T = the abscissa values
- gpd = gates per decade
- sigma = estimate of standard deviation for theoretical gate noise
- stackEfficiency = exponential in theoretical gate noise, 2 represents ideal stacking
- """
-
-
- T2T0 = T2T[0]
- T2TD = T2T[0] - (T2T[1]-T2T[0])
- T2T -= T2TD
-
-
-
-
-
- nd = np.log10(T2T[-1]/T2T[0])
- tdd = np.logspace( np.log10(T2T[0]), np.log10(T2T[-1]), (int)(gpd*nd)+1, base=10, endpoint=True)
- tdl = tdd[0:-1]
- tdr = tdd[1::]
- td = (tdl+tdr) / 2.
-
-
- Vars = np.zeros( len(td) )
- htd = np.zeros( len(td), dtype=complex )
- isum = np.zeros( len(td), dtype=int )
-
- ii = 0
- for itd in range(len(T2T)):
- if ( T2T[itd] > tdr[ii] ):
- ii += 1
-
- tdr[ii-1] = (T2T[itd-1]+T2T[itd])*.5
- tdl[ii ] = (T2T[itd-1]+T2T[itd])*.5
- isum[ii] += 1
- htd[ii] += T2D[ itd ]
- Vars[ii] += sigma**2
-
- td = (tdl+tdr) / 2.
- sigma2 = np.sqrt( Vars * ((1/(isum))**stackEfficiency) )
-
-
-
- td[isum==1] = T2T[0:len(td)][isum==1]
-
- tdd = np.append(tdl, tdr[-1])
-
- htd /= isum
- T2T += T2TD
- return td+T2TD, htd, tdd+T2TD, sigma2, isum
-
- if __name__ == "__main__":
-
- dt = 1e-4
- TT = 1.5
- t = np.arange(0, TT, dt)
- vL = 2057.
- wL = 2.*np.pi*vL
- wL2 = 2.*np.pi*(vL-2.5)
- zeta = -np.pi/6.
- t2 = .150
-
- xs = np.exp(-t/t2) * np.cos(wL2*t + zeta)
- xe = np.exp(-t/t2)
- xn = xs + np.random.normal(0,.1,len(xs))
-
-
-
-
- T = 50
- DT = .002
-
-
- [Q, I, tt] = quadrature(T, vL, wL, dt, xn, DT, t)
- [E0,df,phi,T2] = quadratureDetect(Q, I, tt)
- print("df", df)
- D = RotateAmplitude(I, Q, phi, df, tt)
-
- fig = plt.figure(figsize=[pc2in(20), pc2in(14)])
- ax1 = fig.add_axes([.125,.2,.8,.7])
-
- ax1.plot(tt*1e3, D.imag, label="CA", color='red')
- ax1.plot(t*1e3, xn, color='blue', alpha=.25)
- ax1.plot(tt*1e3, I, label="inphase", color='blue')
- ax1.plot(tt*1e3, Q, label="quadrature", color='green')
-
-
-
-
- GT, GD = gateIntegrate( D.imag, tt, 10 )
- GT, GDR = gateIntegrate( D.real, tt, 10 )
- GT, GQ = gateIntegrate( Q, tt, 10 )
- GT, GI = gateIntegrate( I, tt, 10 )
-
-
-
-
-
-
- ax1.set_xlabel(r"time [ms]")
- ax1.set_ylim( [-1.25,1.65] )
-
-
- legend = plt.legend( frameon=True, scatterpoints=1, numpoints=1, labelspacing=0.2 )
-
- fixLeg(legend)
-
-
-
-
-
-
- spines_to_remove = ['top', 'right']
- for spine in spines_to_remove:
- ax1.spines[spine].set_visible(False)
-
-
- ax1.get_xaxis().tick_bottom()
- ax1.get_yaxis().tick_left()
-
- plt.savefig('rotatetime.pdf',dpi=600)
- plt.savefig('rotatetime.eps',dpi=600)
-
-
- plt.figure()
- plt.plot( tt*1e3, D.real, label="CA", color='red' )
-
- plt.show()
- exit()
|