Esempio n. 1
0
 def Fit(self):
     """
     Fits a two-port RLGC model for the specified s-parameter file
     """
     sp = SParameterFile(self.spfile, self.Z0)
     stepResponse = sp.FrequencyResponse(2, 1).ImpulseResponse().Integral()
     threshold = (stepResponse[len(stepResponse) - 1] +
                  stepResponse[0]) / 2.0
     for k in range(len(stepResponse)):
         if stepResponse[k] > threshold: break
     dly = stepResponse.Times()[k]
     rho = sp.FrequencyResponse(
         1, 1).ImpulseResponse().Integral(scale=False).Measure(dly)
     Z0 = sp.m_Z0 * (1. + rho) / (1. - rho)
     L = dly * Z0
     C = dly / Z0
     guess = [0., L, 0., C, 0., 0.]
     fitter = RLGCFitter(sp, guess)
     (R, L, G, C, Rse, df) = [r[0] for r in fitter.Solve().Results()]
     #         print "series resistance: "+ToSI(R,'ohm')
     #         print "series inductance: "+ToSI(L,'H')
     #         print "shunt conductance: "+ToSI(G,'S')
     #         print "shunt capacitance: "+ToSI(C,'F')
     #         print "skin-effect resistance: "+ToSI(Rse,'ohm/sqrt(Hz)')
     #         print "dissipation factor: "+ToSI(df,'')
     s = self.scale
     self.RLGC = TLineTwoPortRLGCAnalytic(self.m_f,
                                          R * s,
                                          Rse * s,
                                          L * s,
                                          G * s,
                                          C * s,
                                          df,
                                          Z0=50.)
     return self.RLGC
    def InitializeFrequency(self, f):
        """Initializes frequencies
        @param f list of frequencies
        Calibration standards are initialized to have the s-parameters of the standards as defined by the
        frequencies and calibration constants.

        Once intialized, the s-parameters of the calibration standards can be accessed and used.
        @see openStandard
        @see shortStandard
        @see loadStandard
        @see thruStandard
        """
        self.m_f = f
        self.openStandard = OpenStandard(
            self.m_f, self.Constants.openOffsetDelay,
            self.Constants.openOffsetZ0, self.Constants.openOffsetLoss,
            self.Constants.openC0, self.Constants.openC1,
            self.Constants.openC2, self.Constants.openC3)
        self.shortStandard = ShortStandard(
            self.m_f, self.Constants.shortOffsetDelay,
            self.Constants.shortOffsetZ0, self.Constants.shortOffsetLoss,
            self.Constants.shortL0, self.Constants.shortL1,
            self.Constants.shortL2, self.Constants.shortL3)
        self.loadStandard = LoadStandard(self.m_f,
                                         self.Constants.loadOffsetDelay,
                                         self.Constants.loadOffsetZ0,
                                         self.Constants.loadOffsetLoss,
                                         self.Constants.loadZ)
        self.thruStandard = ThruStandard(self.m_f,
                                         self.Constants.thruOffsetDelay,
                                         self.Constants.thruOffsetZ0,
                                         self.Constants.thruOffsetLoss)
        return self
Esempio n. 3
0
 def __init__(self,
              f,
              filename,
              etfilename,
              portListstring=None,
              calculate=True):
     """Constructor  
     Calculates calibrated or raw s-parameters from a network analyzer.
     @param f list of frequencies to calculate s-parameters
     @param filename string filename containing (usually raw) s-parameters.
     @param etfilename string filename containing error-terms (see Calibration).
     @param portListstring (optional, defaults to None) string containing comma delimited list
     of one-based port numbers to use.  This is so that the error-terms from a large port count calibration
     can be used to make a smaller measurement on less ports, and for port reordering.  Essentially, this
     is the list of network analyzer ports used for the measurement.
     @param calculate (optional, defaults to True) bool that defines the calculation direction.  If calculate
     is True, then the assumption is that the s-parameters provided are raw and the goal is to convert the
     raw s-parameters to calibrated s-parameters.  In the unusual situation where calculate is False, the direction
     is reversed and the assumption is that the s-parameters provided are calibrated and the goal is to convert the
     calibrated s-parameters to raw s-parameters.
     """
     if portListstring != None:
         portlist = [int(p) - 1 for p in portListstring.split(',')]
     else:
         portlist = None
     spraw = SParameterFile(filename).Resample(f)
     calibration = Calibration(0, 0).ReadFromFile(etfilename)
     fixtures = calibration.Fixtures()
     fixtures = [fixture.Resample(f) for fixture in fixtures]
     calibration.InitializeFromFixtures(fixtures)
     if calculate:
         dut = calibration.DutCalculation(spraw, portlist)
     else:
         dut = calibration.DutUnCalculation(spraw, portlist)
     SParameters.__init__(self, f, dut)
 def CheckSParametersResult(self, sp, fileName, text):
     #path=os.getcwd()
     #os.chdir(os.path.dirname(os.path.realpath(__file__)))
     if not os.path.exists(fileName):
         sp.WriteToFile(fileName)
         self.assertTrue(False, fileName + ' not found')
     regression = SParameterFile(fileName, 50.)
     #os.chdir(path)
     self.assertTrue(self.SParametersAreEqual(sp, regression, 0.00001),
                     text + ' incorrect')
    def SParameterRegressionChecker(self,sp,spfilename):
        from SignalIntegrity.Lib.SParameters.SParameterFile import SParameterFile
        currentDirectory=os.getcwd()
        os.chdir(self.path)
        if not os.path.exists(spfilename):
            sp.WriteToFile(spfilename)
            if not self.relearn:
                self.assertTrue(False, spfilename + ' not found')
        regression=SParameterFile(spfilename)
        SpAreEqual=self.SParametersAreEqual(sp, regression,self.SPCompareResolution)
        if not SpAreEqual:
            if SignalIntegrityAppTestHelper.plotErrors:
                import matplotlib.pyplot as plt
                plt.clf()
                plt.title(spfilename)
                plt.xlabel('frequency (Hz)')
                plt.ylabel('amplitude')
                for r in range(regression.m_P):
                    for c in range(regression.m_P):
                        plt.semilogy(regression.f(),[abs(sp[n][r][c]-regression[n][r][c]) for n in range(len(regression))],label='S'+str(r+1)+str(c+1))
                plt.legend(loc='upper right')
                plt.grid(True)
                plt.show()

                for r in range(regression.m_P):
                    for c in range(regression.m_P):
                        plt.clf()
                        plt.title('S'+str(r+1)+str(c+1)+' Magnitude')
                        plt.plot(sp.FrequencyResponse(r+1,c+1).Frequencies(),sp.FrequencyResponse(r+1,c+1).Values('dB'),label='calculated')
                        plt.plot(regression.FrequencyResponse(r+1,c+1).Frequencies(),regression.FrequencyResponse(r+1,c+1).Values('dB'),label='regression')
                        plt.xlabel('frequency (Hz)')
                        plt.ylabel('amplitude (dB)')
                        plt.legend(loc='upper right')
                        plt.grid(True)
                        plt.show()

                        plt.clf()
                        plt.title('S'+str(r+1)+str(c+1)+' Phase')
                        plt.plot(sp.FrequencyResponse(r+1,c+1).Frequencies(),sp.FrequencyResponse(r+1,c+1).Values('deg'),label='calculated')
                        plt.plot(regression.FrequencyResponse(r+1,c+1).Frequencies(),regression.FrequencyResponse(r+1,c+1).Values('deg'),label='regression')
                        plt.xlabel('frequency (Hz)')
                        plt.ylabel('amplitude (dB)')
                        plt.legend(loc='upper right')
                        plt.grid(True)
                        plt.show()

        self.assertTrue(SpAreEqual,spfilename + ' incorrect')
        os.chdir(currentDirectory)
 def ReadStandardsFromFiles(self, filenamePrefix):
     """Reads the standards from s-parameter files.
     @param filenamePrefix string name of prefix for standards file names
     @return self
     Each standard is prefixed with the filenamePrefix provided concatenated with:
     - 'Short.s1p' - for the short standard.
     - 'Open.s1p' - for the open standard.
     - 'Load.s1p' - for the load standard.
     - 'Thru.s2p' - for the thru standard
     @attention This decouples the standards from the calibration constants and is not preferred.
     @see shortStandard
     @see openStandard
     @see loadStandard
     @see thruStandard 
     """
     self.shortStandard = SParameterFile(filenamePrefix + 'Short.s1p')
     self.openStandard = SParameterFile(filenamePrefix + 'Open.s1p')
     self.loadStandard = SParameterFile(filenamePrefix + 'Load.s1p')
     self.thruStandard = SParameterFile(filenamePrefix + 'Thru.s2p')
     return self
class CalibrationKit(object):
    """Class for holding a calibration kit derived from calibration constants"""
    def __init__(self, filename=None, f=None):
        """Constructor
        @param filename (optional) string filename of calibration constants file to read.
        @param f (optional) list of frequencies to define the calibration standards for.
        The calibration constants are initialized to their default as specified in CalibrationConstants.__init__().

        If a filename is specified, the calibration constants are read from the disk.

        If frequencies are provided, the frequencies are initialized and the calibration standards are initialized
        to have the s-parameters of the standards as defined by the frequencies and calibration constants.

        No calibration standards are generated yet if no frequencies are provided.
        @see IntializeFrequency
        """
        self.Constants = CalibrationConstants()
        self.m_f = None
        if not filename is None:
            self.ReadFromFile(filename)
        if not f is None:
            self.InitializeFrequency(f)

    def InitializeFrequency(self, f):
        """Initializes frequencies
        @param f list of frequencies
        Calibration standards are initialized to have the s-parameters of the standards as defined by the
        frequencies and calibration constants.

        Once intialized, the s-parameters of the calibration standards can be accessed and used.
        @see openStandard
        @see shortStandard
        @see loadStandard
        @see thruStandard
        """
        self.m_f = f
        self.openStandard = OpenStandard(
            self.m_f, self.Constants.openOffsetDelay,
            self.Constants.openOffsetZ0, self.Constants.openOffsetLoss,
            self.Constants.openC0, self.Constants.openC1,
            self.Constants.openC2, self.Constants.openC3)
        self.shortStandard = ShortStandard(
            self.m_f, self.Constants.shortOffsetDelay,
            self.Constants.shortOffsetZ0, self.Constants.shortOffsetLoss,
            self.Constants.shortL0, self.Constants.shortL1,
            self.Constants.shortL2, self.Constants.shortL3)
        self.loadStandard = LoadStandard(self.m_f,
                                         self.Constants.loadOffsetDelay,
                                         self.Constants.loadOffsetZ0,
                                         self.Constants.loadOffsetLoss,
                                         self.Constants.loadZ)
        self.thruStandard = ThruStandard(self.m_f,
                                         self.Constants.thruOffsetDelay,
                                         self.Constants.thruOffsetZ0,
                                         self.Constants.thruOffsetLoss)
        return self

    def ReadFromFile(self, filename):
        """Reads the calibration constants from a file
        @param filename string name of file to read calibration constants from
        @return self
        @see CalibrationConstants.ReadFromFile()
        @see CalibrationConstants for file format
        """
        self.Constants = CalibrationConstants().ReadFromFile(filename)
        return self

    def WriteToFile(self, filename, calkitname=None):
        """Write calibration constants to a file
        @param filename string name of calibration constant file to write
        @param calkitname (optional) string containing header information to be placed after the DESCRIPTION:
        in the header information.
        @return self
        @see CalibrationConstants.WriteToFile()
        """
        self.Constants.WriteToFile(filename, calkitname)
        return self

    def WriteStandardsToFiles(self, filenamePrefix=''):
        """Writes the standards to s-parameter files.
        @param filenamePrefix string name of prefix for standards file names
        @return self
        Each standard is prefixed with the filenamePrefix provided concatenated with:
        - 'Short.s1p' - for the short standard.
        - 'Open.s1p' - for the open standard.
        - 'Load.s1p' - for the load standard.
        - 'Thru.s2p' - for the thru standard
        @attention the member variables for the standards must exist.
        @see shortStandard
        @see openStandard
        @see loadStandard
        @see thruStandard
        """
        self.shortStandard.WriteToFile(filenamePrefix + 'Short')
        self.openStandard.WriteToFile(filenamePrefix + 'Open')
        self.loadStandard.WriteToFile(filenamePrefix + 'Load')
        self.thruStandard.WriteToFile(filenamePrefix + 'Thru')
        return self

    def ReadStandardsFromFiles(self, filenamePrefix):
        """Reads the standards from s-parameter files.
        @param filenamePrefix string name of prefix for standards file names
        @return self
        Each standard is prefixed with the filenamePrefix provided concatenated with:
        - 'Short.s1p' - for the short standard.
        - 'Open.s1p' - for the open standard.
        - 'Load.s1p' - for the load standard.
        - 'Thru.s2p' - for the thru standard
        @attention This decouples the standards from the calibration constants and is not preferred.
        @see shortStandard
        @see openStandard
        @see loadStandard
        @see thruStandard 
        """
        self.shortStandard = SParameterFile(filenamePrefix + 'Short.s1p')
        self.openStandard = SParameterFile(filenamePrefix + 'Open.s1p')
        self.loadStandard = SParameterFile(filenamePrefix + 'Load.s1p')
        self.thruStandard = SParameterFile(filenamePrefix + 'Thru.s2p')
        return self
Esempio n. 8
0
 def _ProcessCalibrationLine(self, line):
     """processes a line of a netlist, handing calibration specific commands.  
     Lines that can be processed at this level are processed and lines that
     are unknown are place in a list of unknown lines for upstream processing.  This
     enables derived classes to benefit from what this class knows how to process and
     to simply add specific functionality.  As a simple example, a derived simulator class
     needs to add output probes, and this simple system description class knows nothing of
     this.  
     netlist lines that are handled at this level are:
     - 'calibration' - handling of calibration measurements
     @todo document the exact syntax of the netlist lines processed here.
     """
     lineList = self.ReplaceArgs(line.split())
     if len(lineList) == 0: return
     if lineList[0] == 'calibration':
         if self.calibrationMeasurementList == None:
             self.calibrationMeasurementList = []
         if lineList[1] in ['reflect', 'thru', 'xtalk']:
             if self.calibrationMeasurementList is None:
                 self.calibrationMeasurementList = []
             measDict = {}
             measDict['type'] = lineList[1]
             for i in range(2, len(lineList), 2):
                 tokenName, tokenValue = lineList[i], lineList[i + 1]
                 if tokenName == 'file':
                     measDict['raw'] = SParameterFile(tokenValue).Resample(
                         self.m_f)
                 elif tokenName == 'std':
                     if tokenValue == 'None':
                         self.m_spc[tokenValue] = None
                     elif not tokenValue in self.m_spc:
                         self.m_spc[tokenValue] = SParameterFile(
                             tokenValue).Resample(self.m_f)
                     measDict['std'] = self.m_spc[tokenValue]
                 elif tokenName == 'pn':
                     measDict['driven'] = port = int(tokenValue)
                     self.ports = max(port, self.ports)
                 elif tokenName == 'opn':
                     measDict['other'] = port = int(tokenValue)
                     self.ports = max(port, self.ports)
                 elif tokenName == 'ct':
                     measDict['thrutype'] = tokenValue
             if measDict['type'] == 'reflect':
                 self.calibrationMeasurementList.append(
                     ReflectCalibrationMeasurement(
                         measDict['raw'].FrequencyResponse(1, 1),
                         measDict['std'], measDict['driven'] - 1))
             elif measDict['type'] == 'thru':
                 if measDict['thrutype'] == 'SOLT':
                     self.calibrationMeasurementList.append(
                         ThruCalibrationMeasurement(
                             measDict['raw'].FrequencyResponse(1, 1),
                             measDict['raw'].FrequencyResponse(2, 1),
                             measDict['std'], measDict['driven'] - 1,
                             measDict['other'] - 1))
                     self.calibrationMeasurementList.append(
                         ThruCalibrationMeasurement(
                             measDict['raw'].FrequencyResponse(2, 2),
                             measDict['raw'].FrequencyResponse(1, 2),
                             measDict['std'], measDict['other'] - 1,
                             measDict['driven'] - 1))
                 elif measDict['thrutype'] == 'SOLR':
                     self.calibrationMeasurementList.append(
                         UnknownThruCalibrationMeasurement(
                             measDict['raw'], measDict['std'],
                             measDict['driven'] - 1, measDict['other'] - 1))
             elif measDict['type'] == 'xtalk':
                 self.calibrationMeasurementList.append(
                     XtalkCalibrationMeasurement(
                         measDict['raw'].FrequencyResponse(2, 1),
                         measDict['driven'] - 1, measDict['other'] - 1))
                 self.calibrationMeasurementList.append(
                     XtalkCalibrationMeasurement(
                         measDict['raw'].FrequencyResponse(1, 2),
                         measDict['other'] - 1, measDict['driven'] - 1))
     else:
         self.m_ul.append(line)