def dc_current_gain(self, input_current_source, output_ammeter):
     """
     method to perfom .tf to measur a input current souce to ouput ammeter
     
     wich is eqivlint to the SPICE statoemt
     ```
     .tf(I(<output_ammeter>) , <input_current_source>)
     ```
     it will retun the input resitince looking from the input souce to the output measure, the ouput resitince looking
     from the ouput meassue to the input current souce, and finaly the current gain of the input current souce to ouput meassure
     
     Args:
         input_current_source (SKiDl Linear Current Souce obj): the input current souce given as a SKiDl linear depened current souce like
             object. 
        
         output_ammeter (SKiDl Linear Voltage Souce obj; None): This may be a already esisitng linear voltage souce or a 0V linear voltage souce 
             SPICE ammeater add speficly to meassure the current
     
     Returns:
         results from this usge of .tf to measre the current to current gain will be stored in `self.ig_results`
         
     """
     assert input_current_source.ref_prefix=='I', 'current gain must be sourced from a current source'
     assert output_ammeter.ref_prefix=='V', 'current gain must be meassured from a voltage source'
     
     input_src=get_skidl_spice_ref(input_current_source)
     output_src=get_skidl_spice_ref(output_ammeter)
     
     self.tf_res=self.sim.tf(f'I({output_src})', input_src)
     
     self.ig_results=pd.DataFrame(columns=['loc', 'value', 'units'])
         
     for k, v in self.tf_res.nodes.items():
         if 'Transfer_function' in k:
             self.ig_results.at['DC_Igain']=[f'{output_src}/{input_src}', v.as_ndarray()[0], '[A/A]']
         elif 'Input_impedance' in k:
             self.ig_results.at['Input_resistance']=[input_src, v.as_ndarray()[0], '[Ohm]']
         elif 'Output_impedance' in k:
             self.ig_results.at['Output_resistance']=[output_src, v.as_ndarray()[0], '[Ohm]']
         else:
             warnings.warn(f'unexspected addintal outputs `{k, v}`')
    def dc_transresistance(self, input_current_source, output_node_pos=None , output_node_neg='0', output_voltag_source=None):
        
        """
        method to perfom .tf to fine the output voltge to input current.
        via measuring from an input current souce to either a node pair
        wich is eqivlint to the SPICE statoemt
        ```
        .tf(V(<node_1>, <node_2>) , <current_souce_in>)
        ```
        where `<node_2>` can be ommited where then seconed node is always the ground node
        or a seconed output voltage souce can be used in wich case this meothd is then eqivlitnt to 
        ```
        .tf(<voltage_souce_out> , <current_souce_in>)
        ```
        it will retun the input resitince looking from the input souce to the output measure, the ouput resitince looking
        from the ouput meassue to the input voltage souce, and finaly the transriseiince [A/V] gain of the input current souce to ouput meassure
        
        Args:
            input_voltage_source (SKiDl Linear Current Souce obj): the input current souce given as a SKiDl linear depened current souce like
                object. 
            
            output_node_pos (SKiDL net obj or SPICE net name str; None): If using a voltage souce as the ouput measurment this may be left as None
                else must be filled in with eather a SPICE net name as a string or a SKiDl net complint object where the SPICE
                net name can be exstracted from
            
            output_node_neg (SKiDL net obj or SPICE net name str; '0'): If using a voltage souce as the ouput measurment this may be left as '0' else
                if using measuing from a node pair must be eather a SPICE net name as a string or a SKiDl net complint object where the SPICE
                net name can be exstracted from. If left '0' the measured seconed node of the node pair will be the ground net '0'
            
            output_voltag_source (SKiDl Linear Voltage Souce obj; None): If meauing the ouput from a node pair (`output_node_pos` & `output_node_neg`) this may be 
                left as None. Else when measuing ouput voltge from a voltage souce provined a SKiDl linear depened voltage souce like
                object.
        
        Returns:
            results from this usge of .tf to measre the current to voltage gain will be stored in `self.tr_results`
            
        """
        assert input_current_source.ref_prefix=='I', 'transresistance gain must be sourced from a current source'
        input_src=get_skidl_spice_ref(input_current_source)
        
        #deal with node or source output
        if output_voltag_source!=None:

            if (output_node_pos!=None) & (output_node_neg!='0'):
                warnings.warn( 'If output measurment is from a `V` source, nodes node output location will be ignored')

            output_src=f'V({get_skidl_spice_ref(output_voltag_source)})'
            self.tf_res=self.sim.tf(output_src, input_src)
            
            
            output_src=output_src[2:-1].replace(", ", "-")
            
            self.tr_results=pd.DataFrame(columns=['loc', 'value', 'units'])
            
            for k, v in self.tf_res.nodes.items():
                if 'Transfer_function' in k:
                    self.tr_results.at['DC_Transresistance']=[f'{output_src}/{input_src}', v.as_ndarray()[0], '[V/A]']
                elif 'Input_impedance' in k:
                    self.tr_results.at['Input_resistance']=[input_src, v.as_ndarray()[0], '[Ohm]']
                elif 'output_impedance' in k:
                    self.tr_results.at['Output_resistance']=[output_src, v.as_ndarray()[0], '[Ohm]']
                else:
                    warnings.warn(f'unexspected addintal outputs `{k, v}`')
            
        
        else:
            assert output_node_pos!=None, 'output node must be specfied when not using a `V` source'
            #TODO need to make this assertion stronger to the cirucit under test
            assert repr(type(output_node_pos))=="<class 'skidl.Net.Net'>" or isinstance(output_node_pos, str), '`output_node_pos` must be a SKiDl net or a node string' 
            if repr(type(output_node_pos))=="<class 'skidl.Net.Net'>":
                pos_node=node(output_node_pos)
            else:
                pos_node=output_node_pos
            
            #TODO need to make this assertion stronger to the cirucit under test
            assert repr(type(output_node_neg))=="<class 'skidl.Net.Net'>" or isinstance(output_node_neg, str), '`output_node_neg` must be a SKiDl net or a node string' 
            if repr(type(output_node_neg))=="<class 'skidl.Net.Net'>":
                neg_node=node(output_node_neg)
            else:
                neg_node=output_node_neg
                
                
            output_src=f'V({pos_node}, {neg_node})'
            self.output_src=output_src
            
            self.tf_res=self.sim.tf(output_src, input_src)
            
            self.tr_results=pd.DataFrame(columns=['loc', 'value', 'units'])
            
            output_src='('+output_src[2:-1].replace(", ", "-")+')'
        
            for k, v in self.tf_res.nodes.items():
                if 'Transfer_function' in k:
                    self.tr_results.at['DC_Transresistance']=[f'{output_src}/{input_src}', v.as_ndarray()[0], '[V/A]']
                elif 'Input_impedance' in k:
                    self.tr_results.at['Input_resistance']=[input_src, v.as_ndarray()[0], '[Ohm]']
                elif 'output_impedance' in k:
                    self.tr_results.at['Output_resistance']=[output_src, v.as_ndarray()[0], '[Ohm]']
                else:
                    warnings.warn(f'unexspected addintal outputs `{k, v}`')
YouTubeVideo('SfKw8bHk7-o', width=500, height=400, start=306)


# # CCVS
# A Current-Controlled-Voltage-Souce (CCVS) is a source that reads the current through an element and then scales with a gain [V/A], which has the special name transresistance, owing to the units, to the dependent voltage source. Where to measure for the current controlled part we read the current through the element via a series ammeter with polarity opposite to the direction of the current flow we wish to measure. It is functionally equivalent to a Shunt-Shunt feedback circuit. Alais we still do not have a fundamental circuit element that acts as a CCVS. So as ALL ABOUT ELECTRONICS showed we have to build VCVS out of an assembly of fundamental circuit elements. We construct the following example circuit contain a CCVS, analyze it. We will measure the circuit first by doing a dc sweep of the voltage source to try to understand the transresistance gain of the circuit.

# In[5]:


reset()
r5=R(ref='5', value=5@u_Ohm)
r2=R(ref='2', value=2@u_Ohm)
r10=R(ref='10', value=10@u_Ohm)
vs=V(ref='vs', dc_value=5@u_V)
ix=V(ref='ix', dc_value=0@u_V)
ccvs=H(transresistance=2, control=get_skidl_spice_ref(ix))

ix['p', 'n']+=r2[2], gnd

ccvs['p', 'n']+=r5[1], gnd
r2[1]+=r5[2]
vs['p', 'n']+=r10[1], r2[1]
r10[2]+=gnd

circ=generate_netlist()
print(circ)


# In[6]:

Beispiel #4
0
#invoke our subscript and for kicks have it return the internals to external variables
#that could be fine-tuned outside of there invocation inside the subcircuit
real_vss, real_vsr=real_dcVs('real_vs', dummy_load['p'], gnd, 30@u_V, 20@u_Ohm, True)

circ=generate_netlist()
print(circ)

dc_sweep=dc_ease(circ)
dc_sweep.sweep_DF


# In[30]:


#perform the simulation
dc_sweep.sweep_DF.at[get_skidl_spice_ref(dummy_load)]=[0, 10, 0.1]
dc_sweep.do_dc_sim(get_skidl_spice_ref(dummy_load))
dc_sweep.quick_plot()


# In[31]:


#collect the results 
real_vs_data=dc_sweep.dc_resultsNB_DF
real_vs_data


# In[32]: