Example #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 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)