Source code for tesfdmtools.methods.IQrotate
#!/usr/bin/env python3
'''
.. module:: IQrotate
:synopsis: Rotate I/Q signals of TES pulse
.. moduleauthor:: Cor de Vries <c.p.de.vries@sron.nl>
'''
import numpy
e=numpy.exp(1.0) # define e
[docs]def IQrotate(Isig,Qsig):
'''
Rotate I and Q signals of TES pulse to get an average angle of zero
Args:
* `Isig` = record with I-signal
* `Qsig` = record with Q-signal
Returns:
* `Isig` = record with rotated I-signal
* `Qsig` = record with rotated Q-signal
'''
a,b=numpy.polyfit(Isig,Qsig,1) # fit y=a*x + b
phase=numpy.arctan(a) # get phase (radians)
cc=(Isig+1j*Qsig)*e**(1j*phase) # make rotated complex signal
Inew=numpy.real(cc)
Qnew=numpy.imag(cc)
Inew=Inew-(Inew[0]-Isig[0])
Qnew=Qnew-(Qnew[0]-Qsig[0])
return (Inew,Qnew)
[docs]def IQphase(Isig,Qsig):
'''
Get average angle of TES pulse in I/Q plane
Args:
* `Isig` = record with I-signal
* `Qsig` = record with Q-signal
Returns:
* 'angle` = angle (radians)
'''
# a,b=numpy.polyfit(Isig,Qsig,1) # fit y=a*x + b
ai=(float(Isig.max())+float(Isig.min()))/2.0
aq=(float(Qsig.max())+float(Qsig.min()))/2.0
return numpy.arctan2(aq,ai) # return phase
[docs]def IQphrot(Isig,Qsig,phase):
'''
Rotate I and Q signals of TES pulse with given angle
Args:
* `Isig` = record with I-signal
* `Qsig` = record with Q-signal
* `phase` = phase to be rotated (radians)
Returns:
* `Isig` = record with rotated I-signal
* `Qsig` = record with rotated Q-signal
'''
cc=(Isig+1j*Qsig)*e**(1j*phase) # make rotated complex signal
Inew=numpy.real(cc)
Qnew=numpy.imag(cc)
# Inew=Inew-(Inew[0]-Isig[0])
# Qnew=Qnew-(Qnew[0]-Qsig[0])
return (Inew,Qnew)