示例#1
0
        def noisesolve(s):

            # Calculate the reciprocal G and C matrices
            Yreciprocal = G.T + s*C.T
            
            Yreciprocal2, uu = (tk.toMatrix(A) for A in (Yreciprocal, u))
            
            ## Calculate transimpedances from currents in each nodes to output
            zm =  tk.linearsolver(Yreciprocal2, -uu)

            xn2out = tk.dot(tk.dot(zm.reshape(1, tk.size(zm)), CY), tk.conj(zm))

            ## Etract gain
            gain = None
            if isinstance(self.inputsrc, VS):
                gain = self.cir.extract_i(zm, 
                                          instjoin(self.inputsrc_name, 'plus'),
                                          refnode=refnode, 
                                          refnode_removed=True)
                
            elif isinstance(self.inputsrc, IS):
                plus_node = instjoin(self.inputsrc_name, 'plus')
                minus_node = instjoin(self.inputsrc_name, 'minus')
                gain = self.cir.extract_v(zm, 
                                          self.cir.get_node(plus_node), 
                                          self.cir.get_node(minus_node), 
                                          refnode=refnode, refnode_removed=True)
            return xn2out[0], gain
示例#2
0
    def solve(self, freqs, refnode=gnd, complexfreq = False, u = None):
        G, C, CY, u, x, ss = self.dc_steady_state(freqs, refnode,
                                              complexfreq = complexfreq, u = u)

        tk = self.toolkit
        
        def noisesolve(s):

            # Calculate the reciprocal G and C matrices
            Yreciprocal = G.T + s*C.T
            
            Yreciprocal2, uu = (tk.toMatrix(A) for A in (Yreciprocal, u))
            
            ## Calculate transimpedances from currents in each nodes to output
            zm =  tk.linearsolver(Yreciprocal2, -uu)

            xn2out = tk.dot(tk.dot(zm.reshape(1, tk.size(zm)), CY), tk.conj(zm))

            ## Etract gain
            gain = None
            if isinstance(self.inputsrc, VS):
                gain = self.cir.extract_i(zm, 
                                          instjoin(self.inputsrc_name, 'plus'),
                                          refnode=refnode, 
                                          refnode_removed=True)
                
            elif isinstance(self.inputsrc, IS):
                plus_node = instjoin(self.inputsrc_name, 'plus')
                minus_node = instjoin(self.inputsrc_name, 'minus')
                gain = self.cir.extract_v(zm, 
                                          self.cir.get_node(plus_node), 
                                          self.cir.get_node(minus_node), 
                                          refnode=refnode, refnode_removed=True)
            return xn2out[0], gain

        # Calculate output voltage noise
        if self.outputnodes != None:
            ioutp, ioutn = (self.cir.get_node_index(node) 
                            for node in self.outputnodes)
            u[ioutp] = -1
            u[ioutn] = 1
        # Calculate output current noise
        else:
            plus_term = instjoin(self.outputsrc_name, 'plus')
            branch = self.cir.get_terminal_branch(plus_term)[0]
            ibranch = self.cir.get_branch_index(branch)
            u[ibranch] = -1
            
        ## Refer the voltages to the gnd node by removing
        ## the rows and columns that corresponds to this node
        irefnode = self.cir.nodes.index(refnode)
        G,C,CY,u = remove_row_col((G,C,CY,u), irefnode, tk)
        
        xn2out, gain = self.noise_map_function(noisesolve, ss, refnode)

        # Store results
        result = InternalResultDict()

        if self.outputnodes != None:
            result['Svnout'] = xn2out
        elif self.outputsrc != None:
            result['Sinout'] = xn2out

        # Calculate the gain from the input voltage source by using the 
        # transimpedance vector to find the transfer from the branch voltage of
        # the input source to the output
        if isinstance(self.inputsrc, VS):
            result['gain'] = gain
            result['Svninp'] = xn2out / abs(gain)**2

        elif isinstance(self.inputsrc, IS):
            result['gain'] = gain
            result['Sininp'] = xn2out / abs(gain)**2

        return result