Name | Modified | Size | Downloads / Week |
---|---|---|---|
Core.nb | 2017-11-24 | 9.7 kB | |
InitialRelease.zip | 2017-11-24 | 20.5 kB | |
LC filter optimization.nb | 2017-11-24 | 70.6 kB | |
lcFilterMulti.cir | 2017-11-24 | 138 Bytes | |
README.txt | 2017-11-24 | 2.7 kB | |
Totals: 5 Items | 103.6 kB | 0 |
=== Core.nb === To use Mathematica-SPICE you will need an installation of SPICE (e.g. ngspice, http://ngspice.sourceforge.net/) which can be called from the command line. Next, a working SPICE circuit file (.cir typically) is required. The file should use the standard notation for replacement used by SPICE wherein variables in the code which are to be varied are written {foo}. Having a .STEP command in the file will not affect Mathematica-SPICE since it will be ignored and Mathematica-SPICE’s sweeps will take place instead. Open Core.nb and update the variables that point to the SPICE binary and your circuit file. Three sweep styles are built in: exponential, linear, and list and they may be mixed and matched for all of your variables as required. Update the variable sweepSetup based on your needs. Please note that the first element of each of those sweep configuration is the variable name without the curly braces, i.e. foo not {foo}. Mathematica-SPICE, by default, will check the entire parameter space specified by all your sweeps; this behavior might need to be modified for especially large parameter spaces. The built in functions of Mathematica-SPICE are quite limited, to give the user maximum flexibility. The remainder of this README will follow the included “LC filter optimization” example. === LC filter optimization example === After we create our SPICE file with the circuit of interest (lcFilterMulti.cir) with the relevant free variables (R2, L1, C1) we must set a target for our optimization. In this example, we want to make a filter that has an exponential cutoff at some frequency, cutoffFreq. Make this explicit in the function targetFunction[]. Next, define the sweeps that will be used for our different variables. In this example, each variable uses one of the different sweep styles for illustration purposes. Run the “Configure sweeps” section to populate the parameterSpace variable. As shown in the “Automate” section, we then iterate through the parameter space, calling the generateFile[] function with each vector of variables. This makes a file which is immediately opened using Import[], parsed for the data of interest with Select[], and stored in the variable called spiceData. We then define some error value we seek to minimize, in this case the RMS deviation of the actual circuit response from our desired filter response. Then we simply choose the best result. A few other features which illustrate the power of pairing SPICE with Mathematica are also shown including live plotting as parameter space is explored and the ability to automatically generate a final .cir file that is the optimized case.