├── .gitignore ├── README.rst ├── broken.va ├── clean ├── figures ├── bsim.svg ├── msnm.py ├── msnm.svg ├── noise-vs-bias.svg ├── pnbsim.svg ├── pnoise.svg ├── resistor-broken.svg └── resistor.svg ├── gen-schematics ├── pnbsim.scs ├── pnoise.scs ├── requirements ├── resistor.va ├── runBSIM ├── runPnoise └── runPnoise-vs-bias /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | .*.swp 28 | doc/.build 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | .pytest_cache/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | local_settings.py 59 | db.sqlite3 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # Environments 87 | .env 88 | .venv 89 | env/ 90 | venv/ 91 | ENV/ 92 | env.bak/ 93 | venv.bak/ 94 | 95 | # Spyder project settings 96 | .spyderproject 97 | .spyproject 98 | 99 | # Rope project settings 100 | .ropeproject 101 | 102 | # mkdocs documentation 103 | /site 104 | 105 | # mypy 106 | .mypy_cache/ 107 | 108 | TODO 109 | .bump.cfg 110 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Flicker Noise Formulations in Compact Models 2 | ============================================ 3 | 4 | :Author: Geoffrey Coram, Colin McAndrew, Kiran Gullapalli and Ken Kundert 5 | :Version: 1.2.0 6 | :Released: 2020-11-13 7 | 8 | Includes a resistor model that demonstrates how to properly model flicker noise 9 | in Verilog-A as described in: 10 | 11 | | `Flicker Noise Formulations in Compact Models `_; 12 | | G. J. Coram, C. C. McAndrew, K. K. Gullapalli, and K. S. Kundert; 13 | | IEEE Transactions on CAD, vol. 39, no. 10, October 2020. 14 | 15 | Also included are two circuits. The first is a simple test circuit for the 16 | resistor model. Here Rva is the Verilog-A model and Rref is the resistor model 17 | that is built-in to Spectre. 18 | 19 | .. image:: figures/pnoise.svg 20 | :width: 35% 21 | :align: center 22 | 23 | The second is a circuit that tests the implementation of flicker noise in the 24 | built-in BSIM4 model. 25 | 26 | .. image:: figures/pnbsim.svg 27 | :width: 35% 28 | :align: center 29 | 30 | If you have a recent version of Spectre, you can simulate the circuits directly 31 | and view the results in your favorite waveform viewer. 32 | 33 | If you have Python 3.6 or later, you can also run the simulation scripts, which 34 | re-generate the netlists, run the simulations (in Spectre), and plot the 35 | results. 36 | 37 | To install the script dependencies, run:: 38 | 39 | pip install -r requirements 40 | 41 | Then simply run:: 42 | 43 | ./runPnoise 44 | 45 | or:: 46 | 47 | ./runBSIM 48 | 49 | These run a simulation and plot the results. You have the -v option and the 50 | logfile (.runPnoise.log or .runBSIM.log) to help you out if you run into any 51 | problems. 52 | 53 | You can also run a simulation of the broken resistor model:: 54 | 55 | ./runPnoise --broken 56 | 57 | You can view the signal and waveforms with:: 58 | 59 | > list-psf -f pnoise.raw/pnoise.pnoise -l 60 | > show-psf out 61 | 62 | My rather old version of Spectre (15.1.0) generated the following results: 63 | 64 | 65 | Resistor 66 | -------- 67 | 68 | .. image:: figures/resistor.svg 69 | :width: 600px 70 | :align: center 71 | 72 | The above shows the flicker noise produced by Spectre's built-in resistor 73 | (*RESref*) and the proposed Verilog-A model (*RESva*). In this case the flicker 74 | noise of the built-in resistor model was implemented correctly and both agree. 75 | 76 | Flicker noise in a resistor is a variation or a flickering in the value of the 77 | resistance over time. The variation has a *1/f* power spectrum and is completely 78 | bias independent; it is not affected by the applied signal at all. You can 79 | observe the flickering by applying a DC bias voltage to the resistor. The 80 | result will be a noise in the current with a *1/f* spectrum. In this circuit we 81 | instead apply a sinusoidal voltage with a frequency of 131kHz and no DC 82 | component to observe the flickering. This results in the same *1/f* 83 | characteristic in the noise, but now mixed up to 131kHz as shown in the figure. 84 | 85 | 86 | Broken Resistor 87 | --------------- 88 | 89 | .. image:: figures/resistor-broken.svg 90 | :width: 600px 91 | :align: center 92 | 93 | The above shows the flicker noise produced by Spectre's built-in resistor 94 | (*RESref*) and the traditional Verilog-A model (*RESva*). In this case the 95 | flicker noise of the Verilog-A model is incorrect and the two models 96 | disagree. 97 | 98 | In this case the simulator discards the sign of the sinusoid when performing the 99 | noise calculation. As such, it appears to the resistor that the applied test 100 | signal is not a pure tone sinusoid, but rather a fully rectified sinusoid. So 101 | rather than have a single spectral component at 131kHz, it has components at 102 | each of the even harmonics of 131kHz, meaning it has components at DC, and 103 | 262kHz, 524kHz, etc. The result is that the *1/f* spectrum from the flicker 104 | noise is replicated and shifted up by each harmonic, meaning that there are 105 | peaks at each of the harmonics of the rectified sine wave. The peaks are 106 | equally spaced in frequency, but they appear to be getting closer together at 107 | higher frequencies because the *x*-axis uses logarithmic scaling. 108 | 109 | This problem is further illustrated in the graphs below. In this case both the 110 | built-in resistor and the broken version of the Verilog-A resistor are driven 111 | with a 1Vp sinusoid where the DC offset is swept from 1V to –1V. In the first 112 | and last graphs, the offset is 1V and –1V, so the current through the resistors 113 | never change sign. They are either always positive or always negative. In these 114 | cases, discarding of the sign is of no consequence and the noise computed for 115 | the two resistors agree. There is a peak at *f* = 0 because of the DC component 116 | of the modulation signal, and a peak at *f* = *f₀*, which is the drive 117 | frequency. In the results for the 0 V offset, the built-in resistor only shows 118 | a peak at *f₀*, the drive frequency, whereas the broken resistor shows peaks at 119 | each of the even harmonics of the drive signal because the sign of the drive 120 | signal is lost. 121 | 122 | .. image:: figures/noise-vs-bias.svg 123 | :width: 600px 124 | :align: center 125 | 126 | 127 | BSIM 128 | ---- 129 | 130 | .. image:: figures/bsim.svg 131 | :width: 600px 132 | 133 | The above shows two different flicker noise models implemented in the built-in 134 | BSIM4 model in Spectre. *fnoimod=1* was implemented correctly while *fnoimod=0* 135 | was not. 136 | 137 | A good first order model for flicker noise in MOSFETs is a bias independent 138 | variation in the threshold voltage. This variation tends to modulate the 139 | current passing through the channel. If the channel current is DC you end up 140 | with simple *1/f* noise. However, if the channel current is sinusoidal, the 141 | flicker noise is up-converted to the frequency of the sinuosoid, as seen with 142 | *fnoimod* = 1. However, the implementation of *fnoimod* = 0 discards the sign 143 | of the sinusoid when doing the noise calculation, and so we again see peaks at 144 | each of the even harmonics of the test signal. 145 | -------------------------------------------------------------------------------- /broken.va: -------------------------------------------------------------------------------- 1 | // Resistor model with both thermal and flicker noise 2 | // 3 | // This model demonstrates the wrong way to model flicker noise. It gives 4 | // correct results in noise analyses but the wrong results in pnoise analyses. 5 | // The issue is described in: 6 | // 7 | // Flicker Noise Formulations in Verilog-A Compact Models 8 | // G. J. Coram, C. C. McAndrew, K. K. Gullapalli, and K. S. Kundert 9 | // IEEE Transactions on CAD, vol. 39, no. 10, October 2020 10 | // 11 | // DO NOT USE THIS MODEL. 12 | // 13 | // It is provided only to demonstrate the wrong way to write a flicker noise 14 | // model. 15 | 16 | `include "disciplines.vams" 17 | `include "constants.vams" 18 | 19 | module res_va(a,b); 20 | inout a, b; 21 | electrical a, b; 22 | parameter real R = 100.0 from (0.0:inf); 23 | parameter real KF = 1.0e-6 from [0.0:inf); 24 | parameter real AF = 2.0 from (0.1:inf); 25 | parameter real EF = 1.0 from (-inf:inf); 26 | 27 | analog begin : vaResistor 28 | real Ir, Pn; 29 | Ir = V(a,b)/R; 30 | Pn = KF*pow(abs(Ir), AF); 31 | I(a,b) <+ Ir; 32 | I(a,b) <+ white_noise(4.0*`P_K*$temperature/R, "thermal"); 33 | I(a,b) <+ flicker_noise(Pn, EF, "flicker"); 34 | end 35 | endmodule 36 | -------------------------------------------------------------------------------- /clean: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -rf {pnoise,pnbsim}.{ahdlSimDB,raw,log} 4 | rm -rf .{runPnoise,runBSIM}.log 5 | rm -rf .*.Linux-64.dep *.ahdlcmi 6 | rm -rf build dist flicker_noise.egg-info 7 | -------------------------------------------------------------------------------- /figures/bsim.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 57 | 78 | 79 | 93 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 668 | 677 | 683 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 1079 | 1080 | 1081 | 1142 | 1143 | 1144 | 1147 | 1148 | 1149 | 1152 | 1153 | 1154 | 1157 | 1158 | 1159 | 1162 | 1163 | 1164 | 1165 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1193 | 1214 | 1225 | 1255 | 1281 | 1282 | 1283 | 1284 | 1285 | 1286 | 1287 | 1288 | 1289 | 1290 | 1291 | 1292 | 1293 | 1294 | 1297 | 1298 | 1299 | 1300 | 1301 | 1302 | 1303 | 1304 | 1305 | 1306 | 1307 | 1308 | 1309 | 1310 | 1311 | 1312 | 1313 | 1314 | 1315 | 1316 | 1317 | 1329 | 1335 | 1356 | 1380 | 1396 | 1408 | 1439 | 1468 | 1499 | 1505 | 1522 | 1532 | 1564 | 1584 | 1599 | 1618 | 1650 | 1656 | 1665 | 1686 | 1703 | 1712 | 1713 | 1714 | 1715 | 1716 | 1717 | 1718 | 1719 | 1720 | 1721 | 1722 | 1723 | 1724 | 1725 | 1726 | 1727 | 1728 | 1729 | 1730 | 1731 | 1732 | 1733 | 1734 | 1735 | 1736 | 1737 | 1738 | 1739 | 1740 | 1741 | 1742 | 1743 | 1744 | 1745 | 1746 | 1747 | 1748 | 1749 | 1750 | 1751 | 1752 | 1753 | 1754 | 1755 | 1756 | 1757 | 1758 | 1759 | 1760 | 1761 | 1762 | 1763 | 1764 | 1765 | 1766 | 1767 | 1768 | 1769 | 1770 | 1771 | 1772 | 1773 | 1774 | 1775 | 1776 | 1777 | 1778 | 1779 | 1780 | 1781 | 1782 | 1783 | 1784 | 1785 | 1786 | 1787 | 1788 | 1789 | 1790 | -------------------------------------------------------------------------------- /figures/msnm.py: -------------------------------------------------------------------------------- 1 | # Generates schematic as an .svg file. 2 | # Requires svg_schematic: 3 | # pip install svg-schematic 4 | 5 | from svg_schematic import ( 6 | Schematic, shift, shift_x, shift_y, midpoint, Box, Ground, Label, Source, Wire 7 | ) 8 | 9 | with Schematic(filename = "msnm.svg"): 10 | v = Source(kind='noise', value='S(f)', orient='v') 11 | Ground(C=v.n, orient='v') 12 | 13 | m = Source(C=shift_x(v.p, 200), kind='mult') 14 | Wire([v.p, m.W]) 15 | wm = Wire([m.S, shift_y(m.S, 25)]) 16 | Label(C=wm.e, loc='S', name='m(t)') 17 | Label(C=midpoint(v.p, m.W), loc='N', name='stationary noise') 18 | 19 | wo = Wire([m.E, shift_x(m.E, 210)]) 20 | Label(C=wo.e, kind='arrow', loc='NW', name='cyclostationary noise') 21 | 22 | Box(C=shift(v.C, 100, -3), w=5.5, h=3.2, line_width=0.5, background='none', stroke_dasharray="4 2") 23 | -------------------------------------------------------------------------------- /figures/msnm.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | S(f) 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | m(t) 40 | 41 | 42 | 43 | 44 | 45 | stationary noise 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | cyclostationary noise 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /figures/pnbsim.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 𝘈 sin(2π𝘧₀𝘵) 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 3V 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 𝘈 sin(2π𝘧₀𝘵) 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /figures/pnoise.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 𝘈 sin(2π𝘧₀𝘵) 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Rva 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | Rref 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /figures/resistor-broken.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 57 | 78 | 79 | 93 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 661 | 670 | 676 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 1031 | 1032 | 1033 | 1089 | 1090 | 1091 | 1094 | 1095 | 1096 | 1099 | 1100 | 1101 | 1104 | 1105 | 1106 | 1109 | 1110 | 1111 | 1112 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1147 | 1161 | 1192 | 1201 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1267 | 1291 | 1311 | 1312 | 1313 | 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 1321 | 1322 | 1323 | 1324 | 1325 | 1326 | 1338 | 1344 | 1355 | 1376 | 1388 | 1409 | 1440 | 1460 | 1475 | 1494 | 1526 | 1532 | 1541 | 1562 | 1588 | 1605 | 1606 | 1607 | 1608 | 1609 | 1610 | 1611 | 1612 | 1613 | 1614 | 1615 | 1616 | 1617 | 1618 | 1619 | 1620 | 1621 | 1622 | 1623 | 1624 | 1625 | 1626 | 1627 | 1628 | 1629 | 1630 | 1631 | 1632 | 1633 | 1634 | 1635 | 1636 | 1637 | 1638 | 1639 | 1640 | 1641 | 1642 | 1643 | 1644 | 1645 | 1646 | 1647 | 1648 | 1649 | 1650 | 1651 | 1652 | 1653 | 1654 | 1655 | 1656 | 1657 | 1658 | 1659 | 1660 | 1661 | 1662 | 1663 | 1664 | 1665 | 1666 | 1667 | 1668 | 1669 | 1670 | 1671 | 1672 | 1673 | 1674 | -------------------------------------------------------------------------------- /figures/resistor.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 57 | 78 | 79 | 93 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 661 | 670 | 676 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 971 | 972 | 973 | 1031 | 1032 | 1033 | 1036 | 1037 | 1038 | 1041 | 1042 | 1043 | 1046 | 1047 | 1048 | 1051 | 1052 | 1053 | 1054 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1089 | 1103 | 1134 | 1143 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1209 | 1233 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1280 | 1286 | 1297 | 1318 | 1330 | 1351 | 1382 | 1402 | 1417 | 1436 | 1468 | 1474 | 1483 | 1504 | 1530 | 1547 | 1548 | 1549 | 1550 | 1551 | 1552 | 1553 | 1554 | 1555 | 1556 | 1557 | 1558 | 1559 | 1560 | 1561 | 1562 | 1563 | 1564 | 1565 | 1566 | 1567 | 1568 | 1569 | 1570 | 1571 | 1572 | 1573 | 1574 | 1575 | 1576 | 1577 | 1578 | 1579 | 1580 | 1581 | 1582 | 1583 | 1584 | 1585 | 1586 | 1587 | 1588 | 1589 | 1590 | 1591 | 1592 | 1593 | 1594 | 1595 | 1596 | 1597 | 1598 | 1599 | 1600 | 1601 | 1602 | 1603 | 1604 | 1605 | 1606 | 1607 | 1608 | 1609 | 1610 | 1611 | 1612 | 1613 | 1614 | 1615 | 1616 | -------------------------------------------------------------------------------- /gen-schematics: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from svg_schematic import Ground, Label, MOS, Resistor, Schematic, Source, Wire 4 | from inform import Error, error, os_error 5 | 6 | try: 7 | with Schematic(filename="figures/pnoise.svg", line_width=2): 8 | vmod = Source(value="𝘈 sin(2π𝘧₀𝘵)", kind="sine") 9 | r1 = Resistor(C=vmod.C, xoff=125, name="Rva", orient="v") 10 | r2 = Resistor(C=r1.C, xoff=125, name="Rref", orient="v") 11 | Wire([vmod.p, r2.p]) 12 | Wire([vmod.n, r2.n]) 13 | 14 | with Schematic(filename="figures/pnbsim.svg", right_pad=25, line_width=2): 15 | m = MOS(orient='h-|') 16 | vs = Source(n=m.s, xoff=-25, value="𝘈 sin(2π𝘧₀𝘵)", kind="sine", orient='v-') 17 | Wire([m.s, vs.n]) 18 | Ground(C=vs.p) 19 | vg = Source(p=m.g, xoff=-125, value="3V", kind="vdc") 20 | Wire([m.g, vg.p]) 21 | Ground(C=vg.n) 22 | vd = Source(p=m.d, xoff=25, value="𝘈 sin(2π𝘧₀𝘵)", kind="sine", orient='v') 23 | Wire([m.d, vd.p]) 24 | Ground(C=vd.n) 25 | 26 | except Error as e: 27 | e.report() 28 | except OSError as e: 29 | error(os_error(e)) 30 | -------------------------------------------------------------------------------- /pnbsim.scs: -------------------------------------------------------------------------------- 1 | // BSIM flicker noise simulations 2 | 3 | simulator lang=spectre 4 | 5 | model nchbsim4_f0 bsim4 fnoimod=0 kf=1e-23 af=2 6 | model nchbsim4_f1 bsim4 fnoimod=1 7 | 8 | Vmod (mod 0) vsource type=sine dc=1.0 sinedc=0.0 ampl=100mV freq=131.072kHz 9 | ED (d 0 mod 0) vcvs gain=1 10 | ES (s 0 mod 0) vcvs gain=-1 11 | VG (g 0) vsource dc=3 12 | VB (b 0) vsource dc=-0.2 13 | 14 | MBSIM4f0 (d_f0 g s b) nchbsim4_f0 l=1um w=10um 15 | MBSIM4f1 (d_f1 g s b) nchbsim4_f1 l=1um w=10um 16 | 17 | iRESf0 (d d_f0) vsource dc=0.0 18 | iRESf1 (d d_f1) vsource dc=0.0 19 | Rout (noise 0) resistor isnoisy=no r=100kOhm 20 | Hnoise (noise 0) pccvs coeffs=[0 1 1] probes=[iRESf0 iRESf1] 21 | 22 | noise (noise 0) noise start=4_Hz stop=4.194304MHz dec=2k 23 | pop pss fund=131.072kHz 24 | pnoise (noise 0) pnoise start=4_Hz stop=4.194304MHz dec=2k maxsideband=10 25 | -------------------------------------------------------------------------------- /pnoise.scs: -------------------------------------------------------------------------------- 1 | // Resistor flicker noise simulations 2 | 3 | simulator lang=spectre 4 | 5 | ahdl_include "resistor.va" 6 | 7 | model rref resistor kf=1.0e-6 af=2 // to match res_va 8 | 9 | Vmod (n 0) vsource type=sine dc=1.0 sinedc=0.0 ampl=100mV freq=131.072kHz 10 | Rva (n 0) res_va 11 | Rref (n 0) rref r=100.0 12 | 13 | noise noise start=4_Hz stop=4.194304MHz dec=2k oprobe=Vmod 14 | pss pss fund=131.072kHz maxacfreq=4.194304MHz 15 | pnoise pnoise start=4_Hz stop=4.194304MHz dec=2k maxsideband=10 oprobe=Vmod 16 | -------------------------------------------------------------------------------- /requirements: -------------------------------------------------------------------------------- 1 | # This file is used to install the dependencies for runPnoise and runBSIM. 2 | # You can get the dependencies using either of the following commands: 3 | # pip3 install -r requirements 4 | 5 | docopt 6 | matplotlib 7 | numpy 8 | inform>=1.26 9 | quantiphy>=2.16 10 | psf-utils>=1.5 11 | shlib 12 | svg_schematic>=0.7 13 | -------------------------------------------------------------------------------- /resistor.va: -------------------------------------------------------------------------------- 1 | // Resistor model with both thermal and flicker noise 2 | // 3 | // This model demonstrates the correct way to model flicker noise. It gives 4 | // correct results in both noise and pnoise analyses as described in: 5 | // 6 | // Flicker Noise Formulations in Verilog-A Compact Models 7 | // G. J. Coram, C. C. McAndrew, K. K. Gullapalli, and K. S. Kundert 8 | // IEEE Transactions on CAD, vol. 39, no. 10, October 2020 9 | 10 | `include "disciplines.vams" 11 | `include "constants.vams" 12 | 13 | module res_va(a,b); 14 | inout a, b; 15 | electrical a, b; 16 | parameter real R = 100.0 from (0.0:inf); 17 | parameter real KF = 1.0e-6 from [0.0:inf); 18 | parameter real AF = 2.0 from (0.1:inf); 19 | parameter real EF = 1.0 from (-inf:inf); 20 | 21 | analog function integer sign; 22 | input arg; 23 | real arg; 24 | sign = arg >= 0 ? +1 : -1; 25 | endfunction 26 | 27 | analog begin : vaResistor 28 | real Ir, Pn; 29 | Ir = V(a,b)/R; 30 | Pn = KF*pow(abs(Ir), AF); 31 | I(a,b) <+ Ir; 32 | I(a,b) <+ white_noise(4.0*`P_K*$temperature/R, "thermal"); 33 | I(a,b) <+ flicker_noise(sign(Ir)*Pn, EF, "flicker"); 34 | end 35 | endmodule 36 | -------------------------------------------------------------------------------- /runBSIM: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Description {{{1 3 | """ 4 | Simulate BSIM4 Flicker Noise with PNoise Analysis 5 | 6 | Usage: 7 | runBSIM [options] 8 | 9 | Options: 10 | -v, --verbose turn on verbose mode 11 | 12 | Run a PNoise simulation on BSIM4 transistors, testing the implementation 13 | of the flicker noise model (selected by model parameter fnoimod). In 14 | certain simulators at the time this example was created, the noise spectra 15 | are qualitatively different: the location of the spikes differs, depending 16 | on fnoimod. 17 | 18 | For fnoimod=1, the simulation results are correct: the flicker noise is 19 | up-converted to be centered around f0. The drain-source voltage is small, 20 | so that the transistor is in the linear region. For fnoimod=0, the noise 21 | spectrum differs: the spikes are at different locations, whereas we 22 | expect only different amplitudes. 23 | 24 | The simulation results were reported in the paper "Flicker Noise Formulations 25 | in Verilog-A Compact Models" by G. J. Coram, C. C. McAndrew, K. K. Gullapalli, 26 | and K. S. Kundert; IEEE Transactions on CAD, vol. 39, no. 10, October 2020. 27 | 28 | The frequency and amplitude of the excitation are set by the variables f0 and 29 | ampl in this program. 30 | 31 | 32 | Simulation Parameters: 33 | f0 (fₒ) = 2**17 "Hz" — frequency of the modulating sinusoid 34 | ampl = 100mV — amplitude of the modulating sinusoid 35 | ptsPerCycle = 64 — number of desired points per cycle 36 | cycles = 2048*16 — total number of cycles 37 | T = 1.0/f0 "s" — period of one cycle 38 | dt = T/ptsPerCycle "s" — (desired) time between transient simulation samples 39 | tstop = T*cycles "s" — stop time for transient simulation 40 | fmin = 1.0*int(1.0/tstop) "Hz" — minimum frequency for analysis 41 | fmax = f0*ptsPerCycle/2 "Hz" — maximum frequency for analysis 42 | ptsPerDec = 2000 — number of frequency points per decade 43 | — for the noise analysis 44 | """ 45 | # These simulation parameters are unusual because simulations involving 46 | # transient noise were run during the course of writing the paper, and the 47 | # values used in both the PNoise and transient noise simulations were chosen to 48 | # be consistent. Many of the values defined above are not needed with a simple 49 | # PNoise analysis, and their values need not be so carefully chosen. 50 | 51 | # Imports {{{1 52 | import re 53 | import matplotlib.pyplot as plt 54 | from matplotlib.ticker import FuncFormatter 55 | from numpy import sqrt 56 | from docopt import docopt 57 | from inform import Error, Inform, comment, dedent, display, done, fatal, os_error 58 | from psf_utils import PSF 59 | from quantiphy import Quantity 60 | from shlib import Run, render_command, set_prefs as shlib_set_prefs, to_path 61 | 62 | # Initialization {{{1 63 | cmdline = docopt(__doc__) 64 | 65 | Inform(verbose=cmdline["--verbose"], logfile=True, colorscheme=None) 66 | shlib_set_prefs(use_inform=True) 67 | Quantity.set_prefs(map_sf=Quantity.map_sf_to_greek) 68 | 69 | # Globals {{{1 70 | # plotting preferences {{{2 71 | use_sci_notation = False # axis labels (alternative is to use SI scale factors) 72 | show_power = False # display in V²/Hz if True and V/√Hz otherwise 73 | if use_sci_notation: 74 | adjust_plot_bounds = dict(left=0.2, right=0.98) 75 | else: 76 | adjust_plot_bounds = dict(left=0.15, right=0.98) 77 | 78 | # paths {{{2 79 | spectre_exe = "spectre" # Spectre executable 80 | netlist_file = to_path("pnbsim.scs") # Spectre netlist file 81 | log_file = netlist_file.with_suffix(".log") # Spectre logfile 82 | results_dir = netlist_file.with_suffix(".raw") # simulation results directory 83 | psf_file = results_dir / "pnoise.pnoise" # PNoise PSF file 84 | sim_cmd = (spectre_exe, "=log", log_file, "-format", "psfascii", netlist_file) 85 | 86 | # simulation parameters {{{2 87 | # Extract the simulation parameters from description and add them as local vars 88 | params = Quantity.extract(__doc__) 89 | globals().update(params) 90 | 91 | # generate netlist {{{2 92 | with Quantity.prefs(prec="full", form='sia', spacer="", unity_sf="_"): 93 | netlist = dedent(f""" 94 | // BSIM flicker noise simulations 95 | 96 | simulator lang=spectre 97 | 98 | model nchbsim4_f0 bsim4 fnoimod=0 kf=1e-23 af=2 99 | model nchbsim4_f1 bsim4 fnoimod=1 100 | 101 | Vmod (mod 0) vsource type=sine dc=1.0 sinedc=0.0 ampl={ampl} freq={f0} 102 | ED (d 0 mod 0) vcvs gain=1 103 | ES (s 0 mod 0) vcvs gain=-1 104 | VG (g 0) vsource dc=3 105 | VB (b 0) vsource dc=-0.2 106 | 107 | MBSIM4f0 (d_f0 g s b) nchbsim4_f0 l=1um w=10um 108 | MBSIM4f1 (d_f1 g s b) nchbsim4_f1 l=1um w=10um 109 | 110 | iRESf0 (d d_f0) vsource dc=0.0 111 | iRESf1 (d d_f1) vsource dc=0.0 112 | Rout (noise 0) resistor isnoisy=no r=100kOhm 113 | Hnoise (noise 0) pccvs coeffs=[0 1 1] probes=[iRESf0 iRESf1] 114 | 115 | noise (noise 0) noise start={fmin} stop={fmax} dec={ptsPerDec} 116 | pop pss fund={f0} 117 | pnoise (noise 0) pnoise start={fmin} stop={fmax} dec={ptsPerDec} maxsideband=10 118 | """) 119 | netlist_file.write_text(netlist.lstrip()) 120 | 121 | # output parameters if verbose {{{2 122 | with Quantity.prefs(show_label="f", label_fmt_full="{V:<18} -- {d}"): 123 | comment(f"Parameters:") 124 | for k, v in params.items(): 125 | comment(f" {v:S}") 126 | 127 | # simulate {{{1 128 | try: 129 | comment("\nRunning:") 130 | comment(" ", render_command(sim_cmd, {"=log": 1, "-format": 1})) 131 | spectre = Run(sim_cmd, "sOEW0") 132 | except Error as e: 133 | if e.stdout: 134 | comment(e.stdout) 135 | e.terminate(culprit=spectre_exe, codicil=f"See {log_file} for more information.") 136 | 137 | # plot results {{{1 138 | try: 139 | # Extract data from PSF file 140 | results = PSF(psf_file, sep=":") 141 | sweep = results.get_sweep() 142 | x_name = sweep.name 143 | x_units = sweep.units 144 | x = sweep.abscissa 145 | f0_sig = results.get_signal("MBSIM4f0:fn") 146 | f1_sig = results.get_signal("MBSIM4f1:fn") 147 | if show_power: 148 | y_units = "V²/Hz" 149 | y_f0 = f0_sig.ordinate 150 | y_f1 = f1_sig.ordinate 151 | else: 152 | y_units = "V/√Hz" 153 | y_f0 = sqrt(f0_sig.ordinate) 154 | y_f1 = sqrt(f1_sig.ordinate) 155 | 156 | # build axis formatters 157 | form = "eng" if use_sci_notation else "si" 158 | def format_x_axis_label(value, _): 159 | return Quantity(value, x_units).render(form=form) 160 | 161 | def format_y_axis_label(value, _): 162 | return Quantity(value, y_units).render(form=form) 163 | 164 | x_axis_formatter = FuncFormatter(format_x_axis_label) 165 | y_axis_formatter = FuncFormatter(format_y_axis_label) 166 | 167 | # create the PNoise graph 168 | figure, axes = plt.subplots(1, 1) 169 | # shift the figure a bit to the right to accommodate y-axis labels 170 | figure.subplots_adjust(**adjust_plot_bounds) 171 | axes.plot(x, y_f0, linewidth=2, label="fnoimod0") 172 | axes.plot(x, y_f1, linewidth=2, label="fnoimod1") 173 | axes.legend(frameon=False, loc="best") 174 | axes.set_xscale("log" if results.log_x(sweep) else "linear") 175 | axes.set_yscale("log" if results.log_y(sweep) else "linear") 176 | axes.xaxis.set_major_formatter(x_axis_formatter) 177 | axes.yaxis.set_major_formatter(y_axis_formatter) 178 | plt.suptitle(f"Flicker Noise of BSIM4 Transistors with {f0} Sinusoidal Drive") 179 | with Quantity.prefs( 180 | prec = 2, 181 | map_sf = Quantity.map_sf_to_sci_notation, 182 | output_sf = "YZEPTGMkmunpfazy", 183 | minus = Quantity.minus_sign, 184 | ): 185 | plt.show() 186 | except Error as e: 187 | e.terminate() 188 | except KeyboardInterrupt as e: 189 | done() 190 | -------------------------------------------------------------------------------- /runPnoise: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Description {{{1 3 | """ 4 | Simulate Resistor Flicker Noise with PNoise Analysis 5 | 6 | Usage: 7 | runPnoise [options] 8 | 9 | Options: 10 | -v, --verbose turn on verbose mode 11 | -b, --broken use the broken version of the model 12 | 13 | Run a PNoise simulation on Verilog-A and built-in resistor models exhibiting 14 | flicker noise driven by a sinusoidal excitation. The model "res_va" in the 15 | resistor.va file is used, as is the built-in spectre resistor model. 16 | 17 | The frequency and amplitude of the excitation are set by the variables f0 and 18 | ampl in this program. 19 | 20 | The simulation results were reported in the paper "Flicker Noise Formulations 21 | in Verilog-A Compact Models" by G. J. Coram, C. C. McAndrew, K. K. Gullapalli, 22 | and K. S. Kundert; IEEE Transactions on CAD, vol. 39, no. 10, October 2020. 23 | 24 | The file resistor.va preserves the sign of the modulation. The simulation 25 | results are correct with the flicker noise being up-converted to f0. With the 26 | command-line option --broken, the incorrect implementation of flicker noise, 27 | found in broken.va, is used instead. Here the absolute value causes loss of the 28 | sign of the modulation and you get the incorrect results where the flicker noise 29 | is upconverted to 2*f0 and its harmonics. This is shown in Fig. 2 in the above 30 | paper. 31 | 32 | Simulation Parameters: 33 | f0 (fₒ) = 2**17 "Hz" — frequency of the modulating sinusoid 34 | ampl = 100mV — amplitude of the modulating sinusoid 35 | ptsPerCycle = 64 — number of desired points per cycle 36 | cycles = 2048*16 — total number of cycles 37 | T = 1.0/f0 "s" — period of one cycle 38 | dt = T/ptsPerCycle "s" — (desired) time between transient simulation samples 39 | tstop = T*cycles "s" — stop time for transient simulation 40 | fmin = 1.0*int(1.0/tstop) "Hz" — minimum frequency for analysis 41 | fmax = f0*ptsPerCycle/2 "Hz" — maximum frequency for analysis 42 | ptsPerDec = 2000 — number of frequency points per decade 43 | — for the noise analysis 44 | """ 45 | # These simulation parameters are unusual because simulations involving 46 | # transient noise were run during the course of writing the paper, and the 47 | # values used in both the PNoise and transient noise simulations were chosen to 48 | # be consistent. Many of the values defined above are not needed with a simple 49 | # PNoise analysis, and their values need not be so carefully chosen. 50 | 51 | # Imports {{{1 52 | import matplotlib.pyplot as plt 53 | from matplotlib.ticker import FuncFormatter 54 | from numpy import sqrt 55 | from docopt import docopt 56 | from inform import Error, Inform, comment, dedent, display, done, fatal, os_error 57 | from psf_utils import PSF 58 | from quantiphy import Quantity 59 | from shlib import Run, render_command, set_prefs as shlib_set_prefs, to_path 60 | 61 | # Initialization {{{1 62 | cmdline = docopt(__doc__) 63 | 64 | broken = cmdline["--broken"] 65 | Inform(verbose=cmdline["--verbose"], logfile=True, colorscheme=None) 66 | shlib_set_prefs(use_inform=True) 67 | Quantity.set_prefs(map_sf=Quantity.map_sf_to_greek) 68 | 69 | # Globals {{{1 70 | # plotting preferences {{{2 71 | use_sci_notation = False # axis labels (alternative is to use SI scale factors) 72 | show_power = False # display in V²/Hz if True and V/√Hz otherwise 73 | if use_sci_notation: 74 | adjust_plot_bounds = dict(left=0.2, right=0.98) 75 | else: 76 | adjust_plot_bounds = dict(left=0.15, right=0.98) 77 | 78 | # paths {{{2 79 | spectre_exe = "spectre" # Spectre executable 80 | working_model_file = to_path("resistor.va") # working Verilog-A model file 81 | broken_model_file = to_path("broken.va") # broken Verilog-A model file 82 | netlist_file = to_path("pnoise.scs") # Spectre netlist file 83 | log_file = netlist_file.with_suffix(".log") # Spectre logfile 84 | results_dir = netlist_file.with_suffix(".raw") # simulation results directory 85 | psf_file = results_dir / "pnoise.pnoise" # PNoise PSF file 86 | sim_cmd = (spectre_exe, "=log", log_file, "-format", "psfascii", netlist_file) 87 | 88 | # simulation parameters {{{2 89 | # Extract the simulation parameters from description and add them as local vars 90 | params = Quantity.extract(__doc__) 91 | globals().update(params) 92 | 93 | # generate netlist {{{2 94 | with Quantity.prefs(prec="full", form='sia', spacer="", unity_sf="_"): 95 | model_file = broken_model_file if broken else working_model_file 96 | netlist = dedent(f"""\ 97 | // Resistor flicker noise simulations 98 | 99 | simulator lang=spectre 100 | 101 | ahdl_include "{model_file!s}" 102 | 103 | model rref resistor kf=1.0e-6 af=2 // to match res_va 104 | 105 | Vmod (n 0) vsource type=sine dc=1.0 sinedc=0.0 ampl={ampl} freq={f0} 106 | Rva (n 0) res_va 107 | Rref (n 0) rref r=100.0 108 | 109 | noise noise start={fmin} stop={fmax} dec={ptsPerDec} oprobe=Vmod 110 | pss pss fund={f0} maxacfreq={fmax} 111 | pnoise pnoise start={fmin} stop={fmax} dec={ptsPerDec} maxsideband=10 oprobe=Vmod 112 | """) 113 | netlist_file.write_text(netlist) 114 | 115 | # output parameters if verbose {{{2 116 | with Quantity.prefs(show_label="f", label_fmt_full="{V:<18} -- {d}"): 117 | comment(f"Parameters:") 118 | for k, v in params.items(): 119 | comment(f" {v:S}") 120 | 121 | # simulate {{{1 122 | try: 123 | comment("\nRunning:") 124 | comment(" ", render_command(sim_cmd, {"=log": 1, "-format": 1})) 125 | spectre = Run(sim_cmd, "sOEW0") 126 | except Error as e: 127 | e.terminate(culprit=spectre_exe, codicil=f"See {log_file} for the details") 128 | 129 | # plot results {{{1 130 | try: 131 | # Extract data from PSF file 132 | results = PSF(psf_file, sep=":") 133 | sweep = results.get_sweep() 134 | x_name = sweep.name 135 | x_units = sweep.units 136 | x = sweep.abscissa 137 | va_sig = results.get_signal("Rva:total") 138 | ref_sig = results.get_signal("Rref:total") 139 | if show_power: 140 | y_units = "V²/Hz" 141 | y_va = va_sig.ordinate 142 | y_ref = ref_sig.ordinate 143 | else: 144 | y_units = "V/√Hz" 145 | y_va = sqrt(va_sig.ordinate) 146 | y_ref = sqrt(ref_sig.ordinate) 147 | 148 | # build axis formatters 149 | form = "eng" if use_sci_notation else "si" 150 | def format_x_axis_label(value, _): 151 | return Quantity(value, x_units).render(form=form) 152 | 153 | def format_y_axis_label(value, _): 154 | return Quantity(value, y_units).render(form=form) 155 | 156 | x_axis_formatter = FuncFormatter(format_x_axis_label) 157 | y_axis_formatter = FuncFormatter(format_y_axis_label) 158 | 159 | # create the PNoise graph 160 | figure, axes = plt.subplots(1, 1) 161 | # shift the figure a bit to the right to accommodate y-axis labels 162 | figure.subplots_adjust(**adjust_plot_bounds) 163 | axes.plot(x, y_va, linewidth=2, label="RESva") 164 | axes.plot(x, y_ref, linewidth=2, label="RESref") 165 | axes.legend(frameon=False, loc="best") 166 | axes.set_xscale("log" if results.log_x(sweep) else "linear") 167 | axes.set_yscale("log" if results.log_y(sweep) else "linear") 168 | axes.xaxis.set_major_formatter(x_axis_formatter) 169 | axes.yaxis.set_major_formatter(y_axis_formatter) 170 | plt.suptitle(f"Flicker Noise of Resistor with {f0} Sinusoidal Drive") 171 | with Quantity.prefs( 172 | prec = 2, 173 | map_sf = Quantity.map_sf_to_sci_notation, 174 | output_sf = "YZEPTGMkmunpfazy", 175 | minus = Quantity.minus_sign, 176 | ): 177 | plt.show() 178 | except Error as e: 179 | e.terminate() 180 | except KeyboardInterrupt as e: 181 | done() 182 | -------------------------------------------------------------------------------- /runPnoise-vs-bias: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Description {{{1 3 | """ 4 | Simulate Resistor Flicker Noise with PNoise Analysis 5 | 6 | Usage: 7 | runPnoise [options] 8 | 9 | Options: 10 | -b, --broken use the broken version of the model 11 | -s , --svg produce plot as SVG file rather than display it 12 | -v, --verbose turn on verbose mode 13 | 14 | Run a PNoise simulation on Verilog-A and built-in resistor models exhibiting 15 | flicker noise driven by a sinusoidal excitation. The model "res_va" in the 16 | resistor.va file is used, as is the built-in spectre resistor model. 17 | 18 | The frequency and amplitude of the excitation are set by the variables f0 and 19 | ampl in this program. 20 | 21 | The simulation results were reported in the paper "Flicker Noise Formulations 22 | in Verilog-A Compact Models" by G. J. Coram, C. C. McAndrew, K. K. Gullapalli, 23 | and K. S. Kundert; IEEE Transactions on CAD, vol. 39, no. 10, October 2020. 24 | 25 | The file resistor.va preserves the sign of the modulation. The simulation 26 | results are correct with the flicker noise being up-converted to f0. With the 27 | command-line option --broken, the incorrect implementation of flicker noise, 28 | found in broken.va, is used instead. Here the absolute value causes loss of the 29 | sign of the modulation and you get the incorrect results where the flicker noise 30 | is upconverted to 2*f0 and its harmonics. This is shown in Fig. 2 in the above 31 | paper. 32 | 33 | Simulation Parameters: 34 | f0 (fₒ) = 2**17 "Hz" — frequency of the modulating sinusoid 35 | ampl = 100mV — amplitude of the modulating sinusoid 36 | ptsPerCycle = 64 — number of desired points per cycle 37 | cycles = 2048*16 — total number of cycles 38 | T = 1.0/f0 "s" — period of one cycle 39 | dt = T/ptsPerCycle "s" — (desired) time between transient simulation samples 40 | tstop = T*cycles "s" — stop time for transient simulation 41 | fmin = 1.0*int(1.0/tstop) "Hz" — minimum frequency for analysis 42 | fmax = f0*ptsPerCycle/2 "Hz" — maximum frequency for analysis 43 | ptsPerDec = 2000 — number of frequency points per decade 44 | — for the noise analysis 45 | """ 46 | # These simulation parameters are unusual because simulations involving 47 | # transient noise were run during the course of writing the paper, and the 48 | # values used in both the PNoise and transient noise simulations were chosen to 49 | # be consistent. Many of the values defined above are not needed with a simple 50 | # PNoise analysis, and their values need not be so carefully chosen. 51 | 52 | # Imports {{{1 53 | import re 54 | import matplotlib 55 | import matplotlib.pyplot as plt 56 | from matplotlib.ticker import FuncFormatter 57 | from numpy import sqrt 58 | from docopt import docopt 59 | from inform import Error, Inform, comment, dedent, display, done, fatal, os_error 60 | from psf_utils import PSF 61 | from quantiphy import Quantity 62 | from rkm_codes import from_rkm 63 | from shlib import Run, render_command, set_prefs as shlib_set_prefs, to_path 64 | 65 | # Initialization {{{1 66 | cmdline = docopt(__doc__) 67 | 68 | broken = cmdline["--broken"] 69 | svg_file = cmdline['--svg'] 70 | Inform(verbose=cmdline["--verbose"], logfile=True, colorscheme=None) 71 | shlib_set_prefs(use_inform=True) 72 | Quantity.set_prefs(map_sf=Quantity.map_sf_to_greek, minus=Quantity.minus_sign) 73 | 74 | # Globals {{{1 75 | # plotting preferences {{{2 76 | use_sci_notation = False # axis labels (alternative is to use SI scale factors) 77 | show_power = False # display in V²/Hz if True and V/√Hz otherwise 78 | if use_sci_notation: 79 | adjust_plot_bounds = dict(left=0.2, right=0.98) 80 | else: 81 | adjust_plot_bounds = dict(left=0.15, right=0.98) 82 | 83 | # paths {{{2 84 | spectre_exe = "spectre" # Spectre executable 85 | working_model_file = to_path("resistor.va") # working Verilog-A model file 86 | broken_model_file = to_path("broken.va") # broken Verilog-A model file 87 | netlist_file = to_path("pnoise.scs") # Spectre netlist file 88 | log_file = netlist_file.with_suffix(".log") # Spectre logfile 89 | results_dir = netlist_file.with_suffix(".raw") # simulation results directory 90 | psf_file_prefix = "pnoise.pnoise" # PNoise PSF file base name 91 | sim_cmd = (spectre_exe, "=log", log_file, "-format", "psfascii", netlist_file) 92 | 93 | # simulation parameters {{{2 94 | # Extract the simulation parameters from description and add them as local vars 95 | params = Quantity.extract(__doc__) 96 | globals().update(params) 97 | 98 | # generate netlist {{{2 99 | with Quantity.prefs(prec="full", form='sia', spacer="", unity_sf="_"): 100 | model_file = broken_model_file if broken else working_model_file 101 | netlist = dedent( 102 | f"""\ 103 | // Resistor flicker noise simulations 104 | 105 | simulator lang=spectre 106 | 107 | ahdl_include "{model_file!s}" 108 | 109 | model rref resistor kf=1.0e-6 af=2 // to match res_va 110 | 111 | Vmod (n 0) vsource type=sine dc=0 sinedc=0.0 ampl=1 freq={f0} 112 | Rva (n 0) res_va 113 | Rref (n 0) rref r=100.0 114 | 115 | setVdc_1v0 alter dev=Vmod param="sinedc" value=1.001 116 | pss_1v0 pss fund={f0} maxacfreq={fmax} 117 | pnoise_1v0 pnoise start={fmin} stop={fmax} dec={ptsPerDec} maxsideband=10 oprobe=Vmod 118 | 119 | setVdc_0v5 alter dev=Vmod param="sinedc" value=0.5 120 | pss_0v5 pss fund={f0} maxacfreq={fmax} 121 | pnoise_0v5 pnoise start={fmin} stop={fmax} dec={ptsPerDec} maxsideband=10 oprobe=Vmod 122 | 123 | setVdc_0v0 alter dev=Vmod param="sinedc" value=0 124 | pss_0v0 pss fund={f0} maxacfreq={fmax} 125 | pnoise_0v0 pnoise start={fmin} stop={fmax} dec={ptsPerDec} maxsideband=10 oprobe=Vmod 126 | 127 | setVdc_n0v5 alter dev=Vmod param="sinedc" value=-0.5 128 | pss_n0v5 pss fund={f0} maxacfreq={fmax} 129 | pnoise_n0v5 pnoise start={fmin} stop={fmax} dec={ptsPerDec} maxsideband=10 oprobe=Vmod 130 | 131 | setVdc_n1v0 alter dev=Vmod param="sinedc" value=-1.001 132 | pss_n1v0 pss fund={f0} maxacfreq={fmax} 133 | pnoise_n1v0 pnoise start={fmin} stop={fmax} dec={ptsPerDec} maxsideband=10 oprobe=Vmod 134 | """ 135 | ) 136 | netlist_file.write_text(netlist) 137 | 138 | # output parameters if verbose {{{2 139 | with Quantity.prefs(show_label="f", label_fmt_full="{V:<18} -- {d}"): 140 | comment(f"Parameters:") 141 | for k, v in params.items(): 142 | comment(f" {v:S}") 143 | 144 | # simulate {{{1 145 | try: 146 | comment("\nRunning:") 147 | comment(" ", render_command(sim_cmd, {"=log": 1, "-format": 1})) 148 | spectre = Run(sim_cmd, "sOEW0") 149 | except Error as e: 150 | if e.stdout: 151 | comment(e.stdout) 152 | e.terminate(culprit=spectre_exe, codicil=f"See {log_file} for more information.") 153 | 154 | # plot results {{{1 155 | try: 156 | # create the PNoise graph 157 | if svg_file: 158 | matplotlib.use('SVG') 159 | figure, all_axes = plt.subplots(5, 1, figsize=(8, 16)) 160 | figure.subplots_adjust(top=0.97, bottom=0.03, hspace=0.5, **adjust_plot_bounds) 161 | # shift the figure a bit to the right to accommodate y-axis labels 162 | 163 | for i, name in enumerate('1v0 0v5 0v0 n0v5 n1v0'.split()): 164 | 165 | # Extract data from PSF file 166 | psf_file = results_dir / f"pnoise_{name}.pnoise" 167 | results = PSF(psf_file, sep=":") 168 | sweep = results.get_sweep() 169 | x_name = sweep.name 170 | x_units = sweep.units 171 | x = sweep.abscissa 172 | va_sig = results.get_signal("Rva:total") 173 | ref_sig = results.get_signal("Rref:total") 174 | if show_power: 175 | y_units = "V²/Hz" 176 | y_va = va_sig.ordinate 177 | y_ref = ref_sig.ordinate 178 | else: 179 | y_units = "V/√Hz" 180 | y_va = sqrt(va_sig.ordinate) 181 | y_ref = sqrt(ref_sig.ordinate) 182 | 183 | # build axis formatters 184 | form = "eng" if use_sci_notation else "si" 185 | def format_x_axis_label(value, _): 186 | return Quantity(value, x_units).render(form=form) 187 | 188 | def format_y_axis_label(value, _): 189 | return Quantity(value, y_units).render(form=form) 190 | 191 | x_axis_formatter = FuncFormatter(format_x_axis_label) 192 | y_axis_formatter = FuncFormatter(format_y_axis_label) 193 | 194 | # build the sub-graph 195 | axes = all_axes[i] 196 | axes.plot(x, y_va, linewidth=2, label="RESva") 197 | axes.plot(x, y_ref, linewidth=2, label="RESref") 198 | axes.legend(frameon=False, loc="best") 199 | axes.set_xscale("log" if results.log_x(sweep) else "linear") 200 | axes.set_yscale("log" if results.log_y(sweep) else "linear") 201 | axes.xaxis.set_major_formatter(x_axis_formatter) 202 | axes.yaxis.set_major_formatter(y_axis_formatter) 203 | axes.set_title(f"DC level = {from_rkm(name)}", pad=-225) 204 | #plt.suptitle(f"Flicker Noise of Resistor with {f0} Sinusoidal Drive") 205 | with Quantity.prefs( 206 | prec = 2, 207 | map_sf = Quantity.map_sf_to_sci_notation, 208 | output_sf = "YZEPTGMkmunpfazy", 209 | ): 210 | if svg_file: 211 | plt.savefig(svg_file) 212 | else: 213 | plt.show() 214 | except Error as e: 215 | e.terminate() 216 | except KeyboardInterrupt as e: 217 | done() 218 | --------------------------------------------------------------------------------