Exemplo n.º 1
0
def GetFr(sweepdata_folder, sweepdata_file, IQCalibrationfile, IQReffolder, IQReffilename):
    ### Read IQ Sweep data
    freq, I, Q = reader.ReadSweep(sweepdata_folder, sweepdata_file)
    ### Get IQ Mixer calibration data for sweep data frequency
    paras = IQ.IQ_GetPara(IQCalibrationfile, int(round(freq[len(freq)/2]/1e6)))
    ### Calibrate IQ Sweep data
    I_mixercalibrated, Q_mixercalibrated = IQ.IQ_CorrtBarends(paras,I,Q)

    ### Normalize calibrated IQ Sweep data to IQ reference data
    ### Get complex IQ
    IQ_normalized = IQ.IQ_Normalize_Sweep(freq, I_mixercalibrated, Q_mixercalibrated, IQReffolder, IQReffilename)
    x_c, x_c_err, y_c, y_c_err, radius, radius_err, circle_fit_report, theta0, theta0_err, fr, fr_err, Qr, Qr_err, Qc, Qc_err, Qi, Qi_err, fit_report_phase = Fit_IQ_Sweep(freq, IQ_normalized)
    return int(round(fr))
Exemplo n.º 2
0
plt.figure(figsize=(18.5, 10.5))
for n in range(0, num):
    ### Get file name and resonance frequency
    sweepdata_file = sweeplist[n]
    noisedata_file = noiselist[n]
    resfreq = float(resfreqlist[n])

    #   Read data
    sweepfreq, sweepI, sweepQ = reader.ReadSweep(data_folder, sweepdata_file)
    fsample, number, noiseI, noiseQ = reader.ReadNoise(data_folder,
                                                       noisedata_file)
    meastime = len(number) / float(fsample)

    #   Get IQ Mixer calibration parameter
    resfreqinMHz = int(round(sweepfreq[len(sweepfreq) / 2] / 1e6))
    paras = IQ.IQ_GetPara(IQCalibrationfile, resfreqinMHz)

    #   Calibrate IQ data
    I_mixercalibrated, Q_mixercalibrated = IQ.IQ_CorrtBarends(
        paras, sweepI, sweepQ)
    noiseI_mixercalibrated, noiseQ_mixercalibrated = IQ.IQ_CorrtBarends(
        paras, noiseI, noiseQ)

    #   Normalize calibrated IQ Sweep data to IQ reference data
    #   Get complex IQ
    sweepIQ_normalized = IQ.IQ_Normalize_Sweep(sweepfreq, I_mixercalibrated,
                                               Q_mixercalibrated, IQReffolder,
                                               IQReffilename)
    noiseIQ_normalized = IQ.IQ_Normalize_Noise(resfreq, noiseI_mixercalibrated,
                                               noiseQ_mixercalibrated,
                                               IQReffolder, IQReffilename)
import numpy as np
import matplotlib.pyplot as plt
import IQMixer.IQCalib as IQ
import Analyse_PSD as PSD
import FileReader as reader

IQCorrectionfile = 'IQMixer_Calib/20160803_1M_BOX/EllipseFit_0dBm_2000MHz_8000MHz.csv'
folder = '../../../MeasurementResult/'
filename = 'Noise_19dBm_4000MHz_2000K_1S_2'
freq = 4000

fs, num, I, Q = reader.ReadNoise(folder, filename)
paras = IQ.IQ_GetPara(IQCorrectionfile, freq)
Icrr, Qcrr = IQ.IQ_CorrtBarends(paras, I, Q)
IQ = (Icrr + 1j * Qcrr) / np.sqrt(np.mean(Qcrr)**2 + np.mean(Icrr)**2)

revisetheta = -np.arctan2(np.mean(IQ.imag), np.mean(IQ.real))
noisecompfinalrevised = IQ * np.exp(1j * revisetheta)

fx, Pxx, fy, Pyy, fxy, Pxy = PSD.Full_Spectrum(IQ.real, IQ.imag, fs)
fxr, Pxxr, fyr, Pyyr, fxyr, Pxyr = PSD.Full_Spectrum(
    noisecompfinalrevised.real, noisecompfinalrevised.imag, fs)

plt.plot(fx, 10 * np.log10(Pxx), label='ONres  Amplitude ')
plt.plot(fy, 10 * np.log10(Pyy), label='ONres  Phase')
plt.plot(fxr, 10 * np.log10(Pxxr), label='Ir')
plt.plot(fyr, 10 * np.log10(Pyyr), label='Qr')
plt.xscale('log')
plt.legend()
plt.show()
Exemplo n.º 4
0
import IQMixer.IQCalib as IQ
import numpy as np
import FileReader as reader
from matplotlib.backends.backend_pdf import PdfPages

IQCorrectionfile = 'IQMixer_Calib/20160803_1M_BOX/EllipseFit_0dBm_2000MHz_8000MHz.csv'
"""
Edit folder and file name and measurement frequency in nnnn MHz
"""
cosraydata_folder = "../../../MeasurementResult/20160814_Al_Noguchi/CosmicRay/4579/"
freq = 4579
cosraydata_file = '2000K_0.5S_9624'

###   Calibrate IQ data and calculate amplitude of IQ (IQ)
fs, num, I, Q = reader.ReadCosmicRay(cosraydata_folder, cosraydata_file)
paras = IQ.IQ_GetPara(IQCorrectionfile, freq)
I_mixercalibrated, Q_mixercalibrated = IQ.IQ_CorrtBarends(paras, I, Q)
IQ = np.sqrt((I_mixercalibrated - np.mean(I_mixercalibrated))**2 +
             (Q_mixercalibrated - np.mean(Q_mixercalibrated))**2)

###   Get index of maximum point and
###   cut measurement data 500 points left from the peak and
###   2500 points right from the peak
numleft = 500
numright = 2500
index = IQ.argmax()
Ievent = I_mixercalibrated[index - numleft:index + numright]
Qevent = Q_mixercalibrated[index - numleft:index + numright]
amplitude = np.asarray(IQ[index - numleft:index + numright])
phase = np.arctan2(Qevent, Ievent)
Exemplo n.º 5
0
cosraydata_folder = "../../../MeasurementResult/20160814_Al_Noguchi/CosmicRay/4579/"
freq = 4579
cosraydata_file = '2000K_0.5S_9624'

###   Calibrate IQ data and calculate amplitude of IQ (IQ)
fs, num, I, Q = reader.ReadCosmicRay(cosraydata_folder, cosraydata_file)
paras = IQ.IQ_GetPara(IQCorrectionfile, freq)
I_mixercalibrated, Q_mixercalibrated = IQ.IQ_CorrtBarends(paras,I,Q)
IQ = np.sqrt((I_mixercalibrated-np.mean(I_mixercalibrated))**2 + (Q_mixercalibrated-np.mean(Q_mixercalibrated))**2)

###   Get index of maximum point and 
###   cut measurement data 500 points left from the peak and
###   2500 points right from the peak
numleft = 500
numright = 2500
index = IQ.argmax()
Ievent = I_mixercalibrated[index-numleft:index+numright]
Qevent = Q_mixercalibrated[index-numleft:index+numright]
amplitude = np.asarray(IQ[index-numleft:index+numright])
phase = np.arctan2(Qevent, Ievent)

###   Transfer number to time with microsecond unit 
t = num[index-numleft:index+numright] / fs * 1e6
a, a_err, A, A_err, t0, t0_err, tau, tau_err, taur, taur_err, fit_report, residual = Fitter.Fit_CosmicRay(t, amplitude)
fitresult = Fitter.Fit_CosmicRay_model(t, t0, a, A, tau, taur)

###   Plot data and fitting result and residual
font = {'family': 'serif',
        'color':  'darkred',
        'weight': 'normal',
        'size': 10,
Exemplo n.º 6
0
### Get IQ measurement data
data = []
with open(folder + filename + '.csv', 'r') as f:
    for line in f:
        data.append(map(str, line.split(',')))

frequency = np.asarray(
    [int(float(data[i][0]) / 1e6) for i in range(0, len(data))])
I = np.asarray([float(data[i][1]) for i in range(0, len(data))])
Q = np.asarray(
    [float(data[i][2].replace("\n", "")) for i in range(0, len(data))])
print frequency[0]

### IQMixer calibration file to correct data measured with IQMixer
#   If the BOX is changed, please calibrate IQMixer again
IQCorrectionfile = 'IQMixer_Calib/20160803_1M_BOX/EllipseFit_0dBm_2000MHz_8000MHz.csv'
Icrr = []
Qcrr = []
for i in range(0, len(frequency)):
    paras = IQ.IQ_GetPara(IQCorrectionfile, frequency[i])
    Itemp, Qtemp = IQ.IQ_CorrtBarendsSingle(paras, I[i], Q[i])
    Icrr.append(Itemp)
    Qcrr.append(Qtemp)

### save calibrated result
crrfile = open(folder + filename + '_IQMixerCalibrated.csv', 'w')
fwrite = csv.writer(crrfile)

for i in range(0, len(Icrr)):
    fwrite.writerow([frequency[i], Icrr[i], Qcrr[i]])
crrfile.close()
import numpy as np
import csv
import matplotlib.pyplot as plt
import IQMixer.IQCalib as IQ
import Analyse_Fit_SingleKID as FitSingle
import Analyse_PSD as PSD
import FileReader as reader

IQCorrectionfile = 'IQMixer_Calib/20160803_1M_BOX/EllipseFit_0dBm_2000MHz_8000MHz.csv'
sweepdata_folder = "../../../MeasurementResult/20160814_Al_Noguchi/"
sweepdata_file = 'Sweep_4579MHz'
freq, I, Q = reader.ReadSweep(sweepdata_folder, sweepdata_file)
paras = IQ.IQ_GetPara(IQCorrectionfile, int(round(freq[len(freq) / 2] / 1e6)))
I_mixercalibrated, Q_mixercalibrated = IQ.IQ_CorrtBarends(paras, I, Q)

####   CUT   ####
bandwidth = 1e6
freq, real, imag = reader.CutSweep(bandwidth, freq, I_mixercalibrated,
                                   Q_mixercalibrated)
comp = np.asarray([real[i] + imag[i] * 1j for i in range(0, len(real))])

### Fit ###
tau = 45e-9
a, a_err, alpha, alpha_err, tau, tau_err, phi0, phi0_err, fr, fr_err, Qr, Qr_err, Qc, Qc_err, Qi = FitSingle.Fit_7parameterIQ1(
    freq, comp, tau)
fitIQ1 = a * np.exp(1j * alpha) * np.exp(
    -2 * np.pi * 1j * freq * tau) * (1 - (Qr / Qc * np.exp(1j * phi0)) /
                                     (1 + 2 * 1j * Qr * (freq - fr) / fr))
comptilt = comp * np.exp(2 * np.pi * 1j * freq * tau)
plt.axis('equal')
plt.plot(I_mixercalibrated, Q_mixercalibrated, 'b')
Exemplo n.º 8
0
import numpy as np
import csv
import matplotlib.pyplot as plt
import IQMixer.IQCalib as IQ

folder = ''
filename = 'EllipseFit_-19dBm_3000MHz_3000MHz'
RF_Power = '-19dBm'
RF_Freq_Start = 3000  # MHz
RF_Freq_Interval = 10  # MHz, RF measurement sample every 10 MHz
Frequency = 3000
paras = IQ.IQ_GetPara(folder, filename,
                      (Frequency - RF_Freq_Start) / RF_Freq_Interval)

### Get IQ measurement data
data_file = 'Noise_17dBm_3000MHz_100K_1S_1'
data = []
with open(data_file + '.csv', 'r') as f:
    for line in f:
        data.append(map(str, line.split(',')))

freq = [float(data[i][0]) for i in range(0, len(data))]
I = [float(data[i][1]) for i in range(0, len(data))]
Q = [float(data[i][2].replace("\n", "")) for i in range(0, len(data))]

Icrr, Qcrr = IQ.IQ_CorrtBarends(paras, I, Q)

plt.plot(0, 0, '.')
plt.plot(I, Q, '.')
plt.plot(Icrr, Qcrr, '.')
#plt.show()
        data.append(map(str,line.split(',')))
        
freq = [float(data[i][0]) for i in range(0,len(data))]
I = [float(data[i][1]) for i in range(0,len(data))]
Q = [float(data[i][2].replace("\n", "")) for i in range(0,len(data))]

Icrr, Qcrr = IQ.IQ_CorrtBarends(paras,I,Q)

plt.plot(0,0,'.')
plt.plot(I,Q,'.')
plt.plot(Icrr,Qcrr,'.')
#plt.show()

delay_time = 50e-9
for i in range(0,len(Icrr)):
    Icrr[i] = ((Icrr[i]+1j*Qcrr[i]) * IQ.cable_delay_calib(delay_time,3e9)).real
    Qcrr[i] = ((Icrr[i]+1j*Qcrr[i]) * IQ.cable_delay_calib(delay_time,3e9)).imag

### save calibrated result
folder2= ''
crrfile = open(folder2 + data_file + '_IQDelaycalibrated.csv', 'w')
fwrite = csv.writer(crrfile)

for i in range(0, len(Icrr)):
    fwrite.writerow([Icrr[i], Qcrr[i]])
crrfile.close()

plt.plot(0,0,'.')
plt.plot(Icrr,Qcrr)
plt.show()