Menu

S-Params simulation available

2021-12-13
2023-01-23
1 2 > >> (Page 1 of 2)
  • Alessio Cacciatori

    To all developers of NGSpice:
    I have added the simulation of S-Params with arbitrary number of ports.
    VSRC can be modified, adding the port number, the port impedance.
    S-Params is now a native simulation, derived from AC (syntax is similar).
    e.g. ".SP dec 100 10Meg 1G 1" (Last param being : simulate noise yes / no)
    RF noise simulation is missing and still under development (noise figure etc.) but S-Params are completed.
    They have been checked against a commercial simulator in some simple case.
    The code has been written into MSVC.
    I'd like to contribute to the ngspice development so I may send out the code so that it can be added to the std deployment.
    How could I proceed?
    Best
    Alessio

     
  • Holger Vogt

    Holger Vogt - 2021-12-13

    Alessio,

    that sounds great! Many thanks!

    You may create a diff file and post it here. If you are unfamiliar with this procedure, you might zip all files changed and post them here as a zip file.

    What is the basis of your development (what ngspice git branch and status or what release)?

    Currently I am working on ngspice-36. If this is released, we (after some review) may integrate your code into the then new development branch.

    Holger

     

    Last edit: Holger Vogt 2021-12-13
  • Alessio Cacciatori

    Dear Holger,

    Thank you for your reply and apologies for my late one.

    The basis is ngspice-34.

    Please find attached the source code. You will find modification in VSRC (that now can be defined as ports) and some new file, mainly "span.c"

    There is also a small library to solve dense matrices (real / complex) which is needed to do calculation at ports.

    To enable the features, there's the RFSPICE preprocessor flag that has to be defined.

    Example of VSRC as power ports

    V1 in 0 dc 0 ac 1 portnum 1 z0 100 pwr 0.001 freq 2.3e9
    V1 in 0 dc 1 ac 1
    Rpt in x 100
    C1 x 0 1e-9
    Vx x 0 0
    R2 x out 10
    V2 out 0 dc 0 ac 0 portnum 2 z0 50 pwr 0.002 freq 3.2e9
    V2 out 0 dc 0 ac 0

    .sp lin 100 1e8 1e9 1

    My plan is to include sp noise analysis (noise correlation matrixes) which still has to be done (hope to have some time during season holidays).

     
  • Holger Vogt

    Holger Vogt - 2021-12-17

    I have got it up compiling and running under MS Visual Studio.

    Your netlist input file yields constant output versus frequency (see attached raw file). Is that what we have to expect?

     
  • Alessio Cacciatori

    Oh, sorry. There's a left-over due to some experiment.
    Remove Vx from the netlist and you will see some results.
    Best

     
  • Alessio Cacciatori

    (Anyway, S(2,2) was correctly at -0.66 even in your case)

     
  • Alessio Cacciatori

    (Just to clarify: the results you saw with Vx attached are ok: Vx detaches the two ports hence S21 = S12 = 0; S11 = (Zl - Z0)/(Zl+Z0)=(Rpt-100)/(Rpt+100)=0; S22=(10-50)/(10+50))

     
  • Holger Vogt

    Holger Vogt - 2022-01-08

    Alessio,

    I have created a ngspice git branch s-parameters with your code.

    Compiling under MINGW or Linux fails due to 'complexmultiply': too many actual parameters, compiling math/dense/dence.c with VS 2019 succeeds but yields several warnings and errors:

    1>dense.c
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(220,13): warning C4457: declaration of 'r' hides function parameter
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(214,28): message : see declaration of 'r'
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(238,13): warning C4457: declaration of 'r' hides function parameter
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(232,30): message : see declaration of 'r'
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(409,6): warning C4189: 'k': local variable is initialized but not referenced
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(482,1): warning C4133: 'initializing': incompatible types - from 'Mat *' to 'CMat *'
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(569,33): warning C4020: 'complexmultiply': too many actual parameters
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(1098,9): warning C4456: declaration of 'k' hides previous local declaration
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(1096,6): message : see declaration of 'k'
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(1096,6): warning C4189: 'k': local variable is initialized but not referenced
    1>D:\Spice_general\ngspice-master\src\maths\dense\dense.c(1155,6): warning C4189: 'k': local variable is initialized but not referenced
    

    Could you please check the code, remove the warnings and post a new dense.c here?

    Holger

     
  • Alessio Cacciatori

    Dear Holger,

    Please find attached new dense.c and dense.h.

    On my VS2019, the compilation is now clean.

    Could you confirm that it runs smoothly also on Linux?

    Thank you in advance

    Alessio

     

    Last edit: Alessio Cacciatori 2022-01-09
  • Holger Vogt

    Holger Vogt - 2022-01-09

    I have made an update on branch s-parameters, including your new dense.h and .c, but with some extra changes:

    Add new or upgraded functions as of 01-09-22.
    Add a function prototype for cmod.
    Rename function conj to conju because conj
    is already defined differently in complex.h
    

    I have not used the extra extern definitions in dense.h, because they led to a bunch of warning messages when compiled with gcc. Just one function prototype for cmod has been sufficient.

    The code now compiles without s-parameter specific error messages on VS 2019, MINGW gcc, Linux gcc and macOS gcc.

    You may use the code in this branch as basis for further development, if suitable.

     

    Last edit: Holger Vogt 2022-01-09
  • Holger Vogt

    Holger Vogt - 2022-02-17

    Alessio,

    I have not heard from you since some time. Are you still working on updates for ngspice?

    What would be necessary to make ngspice a RF simulator?

    I ask, because I am not a specialist in this field.

    I would like to put your S parameter code onto branch pre-master, so it would become part of ngspice-37. What is missing is some text for our manual. If it is not in the manual, it is not there (because nobody gets to know about it). Could you provide some text (see manual http://ngspice.sourceforge.net/docs/ngspice-36-manual.pdf , chapter 17.9)?

    Holger

     
  • Alessio Cacciatori

    Dear Holger,

    I finally managed to get also SP Noise working.
    Thank you for setting up the github branch... Anyway I had difficulties in setting this up with my MSVC environment so I attach here the updated source.

    Then, as per documentation requirements:

    1. VSRC may be defined as RF Port. To do so, there are two more optional parameters:
      portnum (integer) which define the VSRC as a RF Port.

    Portnum of all VSRCs defined as RF ports must start from 1 and count up to the number of RF ports. You cannot have duplicate portnums.

    Then you have Z0 (real) which define the internal impedance. If not provided, its default value is 50Ohm.

    When declaring a RF ports, the VSRC now become a VSRC with Z0 Ohm in series. This extra resistor affects all simulations.

    If portnum is not provided, VRSC behaves as normal.

    1. SP Simulation
      Syntax is IDENTICAL to .AC except that you have one more optional parameter donoise (0|1).
      SP does always linear S-Matrix simulation and, as outputs, it gives

    S Matrix (size nport x nport where nport is the count of RF ports) which is the Scattering Parameters. It may be used to export Touchstone files (to be implemented yet)...
    Y Matrix (size nport x nport where nport is the count of RF ports) which is the Admittance Matrix
    Z Matrix (size nport x nport where nport is the count of RF ports) which is the Impedance Matrix

    All S|Y|Z output are S_i_j where i and j are integer identifier of the ports. They refer to the portnum identifier of the VSRC corresponding RF port

    If donoise = 0 SP simulation ends here.

    If donoise = 1, SP simulation performs also SP Noise. In this case: you have one more output which is the Noise Current Correlation Matrix: Cy_i_j
    Cy_i_j = <in(i), in*(j)=""> which is the correlation between equivalent input noise current at port i and equivalent input noise current at port j. * stands for conjugate</in(i),>

    When donoise = 1 and you have a two port networks, 4 more outputs are provided:
    Rn which is the input noise resistance (unnormalized)
    NF (dB): noise figure of the 2-ports network
    NFmin (dB): minimum noise figure
    SOpt: optimum input reflection coefficient for noise

    The code has been tested against the same example netlist so, a limited "coverage" but it has been checked against a commercial simulator that I work with.

    At your disposal,

    Alessio

     
    • Holger Vogt

      Holger Vogt - 2022-03-14

      Alessio

      Am 26.02.2022 um 08:41 schrieb Alessio Cacciatori

      S Matrix (size nport x nport where nport is the count of RF ports) which is the Scattering Parameters. It may be used to export Touchstone files (to be implemented yet)...

      This has been available:

      17.5.98 Wrs2p: Write scattering parameters to file (Touchstone® format)

      It has just to be extended to read S_x_y in addition to Sxy.

      See also

      17.9 Scattering parameters (S-parameters)

      of our ngspice manual for the method we have supported so far.

      Y Matrix (size nport x nport where nport is the count of RF ports) which is the Admittance Matrix
      Z Matrix (size nport x nport where nport is the count of RF ports) which is the Impedance Matrix

      All S|Y|Z output are S_i_j where i and j are integer identifier of the ports. They refer to the portnum identifier of the VSRC corresponding RF port

      How do I achieve Y or Z matrices?

      Holger

       
      • Alessio Cacciatori

        Holger,

        Thank you for the update.

        You have Y_i_j and Z_i_j output data to access Y and Z matrices (i,j of course are port indexes).

        In case spnoise is enabled, you also have Cy_i_j.

         
      • Alessio Cacciatori

        Holger,

        Thank you for the update.

        You have Y_i_j and Z_i_j output data to access Y and Z matrices (i,j of course are port indexes).

        In case spnoise is enabled, you also have Cy_i_j.

         
  • Alessio Cacciatori

    Oh, you asked for what is needed to make ngspice a RF simulator.
    Of course, S-Params is the first small step.
    One other thing that would be needed is to
    1. include touchstone file into transient simulations (by IFFT and non-uniform convolution to get transient response of freq.defined components)
    2. Harmonic Balance

    I am giving a look to 1. and 2. but it may take a while, since these are challenging tasks (esp. 2)
    I'll keep you posted.

    Best

     
  • Holger Vogt

    Holger Vogt - 2022-03-29

    I have added the most recent patch made by Alessio to a new git branch s-parameters-2.

     
  • Holger Vogt

    Holger Vogt - 2022-03-29

    Alessio,

    in your example you have two more flags for the VSRC RF port source: pwr an freq . Could you please explain their usage (for the manual)?

    I have just made an update to the manual (chapters 4.1.11, 15.3.8, and 17.5.80), see http://ngspice.sourceforge.net/docs.html.

    Holger

     
  • Alessio Cacciatori

    Hi Holger,

    They are for future HB analysis that I would like to work on in the next weeks.

    They are not used at all for SP analysis. I think that you may exclude those, as of now.

    Alessio

     
  • Holger Vogt

    Holger Vogt - 2022-03-29

    Alessio,

    just another question: In the examples you have port 1 with the option ac 1, port 2 with ac 0. Is there any rule for setting ac 1? What about circuits with three or more ports?

    Could you provide an example with, let's say three ports?

    Holger

     
  • Alessio Cacciatori

    Holger,
    ac is the amplitude of the voltage source during AC simulations. It doesn't have any impact on SP simulations. This way, you may reuse the same voltage source for different simulations.

    If you need to have more than 2 ports, please find the updated example with a 3rd port.
    (V3)...
    Example of VSRC as power ports * *

    V1 in 0 dc 0 ac 1 portnum 1 z0 100
    V1 in 0 dc 1 ac 1
    Rpt in x 100
    C1 x 0 1e-9
    R2 x out 10
    V2 out 0 dc 0 ac 0 portnum 2 z0 50
    V2 out 0 dc 0 ac 0
    V3 x 0 portnum 3 z0 200

    .sp lin 100 1e8 1e9 1
    *.ac dec 100 1 1e8

    By the way: I need to ask you to modify cremovecol as follows

    CMat* cremovecol(CMat* A, int c) {
        CMat* B = newcmatnoinit(A->row, A->col - 1);
        for (int i = 0; i < A->row; i++) {
        int coldest = 0;
    
            for (int j = 0; j < A->col; j++) {
                if (j != c) {
                    B->d[i][coldest] = A->d[i][j];
                    coldest++;
                }
            }
        }
        return B;
    }
    

    And to modify cremovecol2 as follows

    void cremovecol2(CMat* A, CMat* B, int c) {
    
        for (int i = 0; i < A->row; i++) {
            int coldest = 0;
            for (int j = 0; j < A->col; j++) {
                if (j != c) {
                    B->d[i][coldest] = A->d[i][j];
                    coldest++;
                }
            }
        }
        return;
    }
    
     
  • Alessio Cacciatori

    I apologize for my lack of github knowledge: I managed to make a local copy of s-parameters in MSVC but I cannot commit changes...

     
  • Alessio Cacciatori

    I apologize for my lack of github knowledge: I managed to make a local copy of s-parameters in MSVC but I cannot commit changes...

     
  • Holger Vogt

    Holger Vogt - 2022-03-29

    A typical way would be that you create a fork of the ngspice project (started from the ngspice sourcforge git page), then you do your changes and updates, and then you issue a merge request.

    To be honest, I never did this for myself, because I am at the source.

    Another way, if you agree, might be that I add you to the developpers' list. Then you will have direct access to the ngspice git branches, and you may create and care for your own branch(es). Please let me know if this will be of interest to you.

     
  • Alessio Cacciatori

    Thank you Holger, I will try with the fork method... I'll keep you updated.
    Thanks a lot!

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.