home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / cpmug / cpmug083.ark / CMATH.DOC < prev    next >
Encoding:
Text File  |  1984-04-29  |  11.5 KB  |  421 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.        COMPLEX MATH SUBROUTINES FOR CBASIC
  8.  
  9.             by
  10.  
  11.            E.R. LE CLEAR
  12.  
  13.            10/12/1980
  14.  
  15. This file describes a method for  storing  and  using  CBASIC  "public
  16. library"  subroutines  as  well  as  providing  listings  for specific
  17. complex math routines. In order to illustrate the general use of these
  18. subroutines, program LPFILTAN.BAS is provided which  can  be  used  to
  19. predict  the  input  impedance and voltage transfer characteristics of
  20. multiple low pass filters.  
  21.  
  22.        *****  THE PUBLIC LIBRARY  *****
  23.  
  24. Since CBASIC does not normally use line numbers,  the  numeric  lables
  25. required  to  identify  program  transfer  statement  entry  can occur
  26. anywhere in the program and in any order. This allows programs  to  be
  27. written  and  reference  predefined  "line  numbers"   which    define
  28. subprograms  that  can  be  appended  to  the  main  program  prior to
  29. compilation. These subprograms are maintained on the disk as a library
  30. of files that can be  concantenated to the main program. For instance,
  31. suppose that main program file NETWORK.TMP has been written which uses
  32. subroutines  REC/POL  and  POL/REC.  A  CBASIC  source  file  is  then
  33. generated as follows:
  34.  
  35.  
  36. PIP NETWORK.BAS=NETWORK.TMP,REC/POL.SRT,POL/REC.SRT
  37.  
  38.  
  39. The program file NETWORK.BAS now includes all three files concatenated
  40. to form a single program file which is ready to compile and run. Note:
  41. all  of  the  library  subroutine  file  headings  are  of  the format
  42. XXXXXX.SRT .  
  43.  
  44.        *****  COMPLEX MATH SUBROUTINES  *****
  45.  
  46. Basic cannot handle complex math expressions directly.  It is  usually
  47. necessary  to  carry  the real and imaginary parts through the program
  48. separately. For instance, in  order  to  add  two  complex  quantities
  49. (A=B+C), the following program segments might be used:  
  50.  
  51.        BR=WWWW         REAL PART OF B
  52.        BI=XXXX         IMAGINARY PART OF B
  53.        CR=YYYY         REAL PART OF C
  54.        CI=ZZZZ         IMAGINARY PART OF C
  55.        AR=BR+CR        REAL PART OF A
  56.  
  57.  
  58.                                    1
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.        AI=BI+CI        IMAGINARY PART OF A
  68.  
  69.        IE. (AR+JAI)=(BR+JBI)+(CR+JCI)
  70.  
  71. ADDITION and subtraction are straightforward and are  usually  simpler
  72. TO  do in line as they are required.  Complex multiplication, division
  73. and other functions become quite  tedious  to  handle  and  are  prime
  74. candidates for subroutine implementation.
  75.  
  76.  
  77. File DISK.DOC is  the  documentation  file  for  the  author's  CBASIC
  78. complex  math  disk. This File is used to provide documentation of the
  79. disk programs. Removing documentation from individual subroutine files
  80. and accumulating them in a separate documentation file  minimizes  the
  81. length  of  the  final  source  file while a printout provides a handy
  82. reference while writing new programs.  A  brief  description  of  each
  83. subroutine  is  provided including the "line number" of the subroutine
  84. and a definition of the input and output variable formats.
  85.  
  86.  
  87. When a subroutine is used, the appropriate variables must  be  renamed
  88. to  that of the input variable required by the subroutine. In the same
  89. manner, output variables must be renamed if the data is  to  be  saved
  90. for  future use.  Many times, the current output variable can be used 
  91. immediately by the next subroutine without renaming the variables.
  92.  
  93.  
  94. The most commonly used subroutines will be 100.00 through 104.100.  It
  95. is  almost  impossible  to  do  even  the simplest ac circuit analysis
  96. without using one of these.
  97.  
  98.  
  99. Subroutines 105.100 and 106.100 will be useful  in  certain  microwave
  100. engineering calculations while subroutines 107.100 through 111.100 are
  101. used in advanced circuit analysis using matrix algebra.
  102.  
  103.  
  104. Routines 107.100 through 110.100 provide  means  to  change  from  one
  105. matrix type to another. These types are:  
  106.  
  107.        S       SCATTERING MATRIX
  108.        X       TRANSMISSION MATRIX
  109.        Z       IMPEDANCE MATRIX
  110.        Y       ADMITTANCE MATRIX
  111.  
  112. A brief discussion on the relationships between the different matrices
  113. is provided in appendix A.
  114.  
  115.  
  116.  
  117.  
  118.                    2
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. Subroutine   111.100  provides  the  means  for  multiplying  matrices
  128. (primarily x matrices). Matrices must be  multiplied  in  the  correct
  129. direction or errors will result.
  130.  
  131.        *****  APPLICATION PROGRAM  *****
  132.  
  133. File LPFILTAN.BAS is a program for predicting the  characteristics  of
  134. low pass filters with up to 10 sections of the following type:  
  135.  
  136.        ---<LA >---<RLA>---
  137.        1         1
  138.   O--------<CA >---<RCA>--------O
  139.        1
  140.       <RB >
  141.        1
  142.       <LB >
  143.        1
  144.       <CB >
  145.        1
  146.    O-----------------------------O
  147.  
  148. The number of sections is limited by  the  first  DIM  statement.  The
  149. value  can  be changed but 10 sections is more than adaquate to handle
  150. any practical filter.
  151.  
  152.  
  153. The program will first ask for the number of sections  (N),  generator
  154. source  resistance  (RG)  and  load  (RL).   After entering these, the
  155. program will request  values  for  each  component  in  each  section.
  156. Entering a "-" response results in the following:  
  157.  
  158.     COMPONENT           VALUE AUTOMATICALLY ENTERED
  159.     ---------           ---------------------------
  160.     LA,CB               1E+15
  161.     ALL OTHERS               1E-15
  162.  
  163. Any value other than "-" will be entered directly.
  164.  
  165. After entering all component data, the program will ask whether a hard
  166. copy is desired. Any response other than "Y" will cause  the  printout
  167. to be directed to the console.
  168.  
  169.  
  170. The program will next ask for the minimum and maximum frequencies  and
  171. the  number of frequency points to be calculated. These points will be
  172. distributed in a  logrithmic manner so that data can be plotted  on  a
  173. LIN-LOG graph with physically equal spacing.
  174.  
  175.  
  176.  
  177.  
  178.                    3
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187. After calculating and printing the  results  at  all  of  the  desired
  188. frequencies,  the  program will ask if you want to run a new frequency
  189. plot with the same part values (F), rerun the whole program  with  new
  190. values and frequency parameters (P) or quit (Q).
  191.  
  192.  
  193. The following dialog shows the evaluation of  a  six  section  eliptic
  194. filter.  This  particular  filter  is  a low pass prototype. Prototype
  195. filters are  normalized  to  RG=RL=1  and  a  cutoff  frequency  of  1
  196. RADIAN/SEC (.1592 HERTZ).  
  197.  
  198.  
  199.        Program run to evaluate pass band
  200. A>CRUN2 B:LPFILTAN
  201.  
  202. CRUN VER 2.05
  203.                        LOW PASS FILTERS
  204. NUMBER OF SECTIONS ? 6
  205. RG,RL ?  1,1
  206. TYPE IN SECTION PARAMETERS. TYPE - IF ELEMENT NOT USED
  207. FOR SHORTED SERIES ARM, SET RB=1E+15
  208. FOR OPEN SHUNT ARM, SET RB=1E+15
  209. LA,RLA FOR SECTION  1 ? 1.323,-
  210. CA,RCA FOR SECTION  1 ? .0833,-
  211. RB,LB,CB FOR SECTION  1 ? -,-,1.284
  212. LA,RLA FOR SECTION  2 ? 1.011,-
  213. CA,RCA FOR SECTION  2 ? .5563,-
  214. RB,LB,CB FOR SECTION  2 ? -,-,1.807
  215. LA,RLA FOR SECTION 3  ? .7551,-
  216. CA,RCA FOR SECTION  3 ? 1.004,-
  217. RB,LB,CB FOR SECTION  3 ?-,-,1.337
  218. LA,RLA FOR SECTION  4 ? .8300,-
  219. CA,RCA FOR SECTION  4 ? .8402,-
  220. RB,LB,CB FOR SECTION  4 ? -,-,1.204
  221. LA,RLA FOR SECTION  5 ? 1.088,-
  222. CA,RCA FOR SECTION  5 ? .3188,-
  223. RB,LB,CB FOR SECTION  5 ? -,-,1.516
  224. LA,RLA FOR SECTION  6 ? 0,0
  225. CA,RCA FOR SECTION  6 ?-,-
  226. RB,LB,CB FOR SECTION  6 ? -,-,1.087
  227. HARD COPY ? (Y OR N) Y
  228.  
  229.  LOW PASS FILTER ANALYSIS
  230.  
  231. FILTER CONSTANTS
  232.  
  233. RG= 1
  234. RL= 1
  235.  
  236.  
  237.  
  238.                    4
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247. LA 1  = 1.323  RLA 1  = 1E-15
  248. CA 1  = 0.0833 RCA 1  = 1E-15  
  249. RB 1  = 1E-15  LB 1  = 1E-15   CB 1  = 1.284
  250.  
  251. LA 2  = 1.011  RLA 2  = 1E-15
  252. CA 2  = 0.5563 RCA 2  = 1E-15
  253. RB 2  = 1E-15  LB 2  = 1E-15   CB 2  =1.807
  254.  
  255. LA 3  = 0.7751 RLA 3  = 1E-15
  256. CA 3  = 1.004  RCA 3  = 1E-15
  257. RB 3  = 1E-15  LB 3  = 1E-15   CB 3  = 1.337
  258.  
  259. LA 4  = 0.83   RLA 4  = 1E-15
  260. CA 4  = 0.8402 RCA 4  = 1E-15
  261. RB 4  =1E-15   LB 4  = 1E-15   CB 4  =1.204
  262.  
  263. LA 5  = 1.088  RLA 5  = 1E-15
  264. CA 5  = 0.3188 RCA 5  = 1E-15
  265. RB 5  = 1E-15  LB 5  =1E-15    CB 5  =1.516
  266.  
  267. LA 6  = 0      RLA 6  = 0
  268. CA 6  = 1E-15  RCA 6  = 1E-15
  269. RB 6  = 1E-15  LB 6  = 1E-15   CB 6  = 1.087
  270.  
  271. FMIN,FMAX ? .01592,.1592
  272. NUMBER OF DATA POINTS ? 20
  273. FREQ          ALPHA(DB)     ANG(ALPHA)          ZIN        ANG(ZIN)
  274. ---------------------------------------------------------------------
  275. 1.592E-02      -0.09           -37.70       8.401E-01       -13.09
  276. 1.797E-02      -0.11           -42.50       8.101E-01       -13.39
  277. 2.029E-02      -0.13           -47.91       7.779E-01       -13.26
  278. 2.290E-02      -0.15           -54.00       7.451E-01       -12.53
  279. 2.585E-02      -0.16           -60.86       7.142E-01       -11.03
  280. 2.918E-02      -0.18           -68.63       6.890E-01       -8.58
  281. 3.294E-02      -0.18           -77.44       6.751E-01       -5.16
  282. 3.718E-02      -0.16           -87.51       6.798E-01       -1.00
  283. 4.198E-02      -0.13        80.92       7.123E-01       3.16
  284. 4.738E-02      -0.08        67.49       7.809E-01       5.93
  285. 5.349E-02      -0.03        51.78       8.861E-01       5.46
  286. 6.038E-02      -0.00        33.37       9.996E-01       0.03
  287. 6.816E-02      -0.03        11.87       1.037E 00       -9.91
  288. 7.694E-02      -0.12        -13.08       9.289E-01       -18.59
  289. 8.685E-02      -0.18           -42.34       7.677E-01       -17.12
  290. 9.804E-02      -0.08           -78.54       7.693E-01       -3.15
  291. 1.107E-01      -0.02        53.78       1.101E 00       -4.15
  292. 1.249E-01      -0.18        -9.02       9.403E-01       -22.22
  293. 1.410E-01      -0.08        73.88       1.294E 00       -4.34
  294. 1.592E-01      -0.22        26.99       8.275E-01       22.50
  295.  
  296.  
  297.  
  298.                                    5
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.        PROGRAM RUN TO EVALUATE STOP BAND
  309.  
  310. NEW FREQ PLOT(F), NEW PARAMETERS(P) OR QUIT(Q) F
  311. FMIN,FMAX ? .1592,..3184
  312. NUMBER OF DATA POINTS ? 20
  313. FREQ          ALPHA(DB)     ANG(ALPHA)           ZIN        ANG(ZIN)
  314. ----------------------------------------------------------------------
  315. 1.592E-01      -0.22        26.99       8.275E-01       22.50
  316. 1.651E-01      -20.72        83.71       1.815E 01       -87.78
  317. 1.712E-01      -41.30        51.20       2.840E 00       -90.00
  318. 1.776E-01      -63.29        33.29       1.853E 00       -90.00
  319. 1.842E-01      -91.06        20.83       1.450E 00       -90.00
  320. 1.911E-01      -108.44        11.27       1.219E 00       -90.00
  321. 1.982E-01      -89.51        3.52       1.063E 00       -90.00
  322. 2.055E-01      -93.28           -2.99       9.488E-01       -90.00
  323. 2.132E-01      -110.71           -8.60       8.599E-01       -90.00
  324. 2.211E-01      -92.85           -13.52       7.878E-01       -90.00
  325. 2.293E-01      -89.74           -17.90       7.277E-01       -90.00
  326. 2.378E-01      -89.63           -21.84       6.764E-01       -90.00
  327. 2.466E-01      -91.43           -25.41       6.319E-01       -90.00
  328. 2.558E-01      -95.44           -28.68       5.927E-01       -90.00
  329. 2.653E-01      -104.97           -31.69       5.578E-01       -90.00
  330. 2.752E-01      -105.49           -34.47       5.264E-01       -90.00
  331. 2.854E-01      -96.52           -37.05       4.979E-01       -90.00
  332. 2.960E-01      -92.90           -39.45       4.720E-01       -90.00
  333. 3.070E-01      -90.97           -41.71       4.482E-01       -90.00
  334. 3.184E-01      -89.93           -43.82       4.262E-01       -90.00
  335.  
  336.  
  337. NEW FREQ PLOT(F), NEW PARAMETERS(P) OR QUIT(Q) Q
  338.  
  339. A>
  340.  
  341.  
  342.  
  343.  
  344. It should be pointed out that the program  utilizes  the  X  parameter
  345. matrix  to calculate the overall filter characteristics rather than an
  346. elaborate ladder network representation. This results in a simpler and
  347. shorter program. In addition,the program can be  easily  modified  for
  348. other  types  of filter sections without a major rewrite (ie. hi-pass,
  349. bandpass and bandstop). In  order  to  simplify  programming,  a  unit
  350. matrix  is  defined  prior to entering the matrix multiplication loop.
  351. This allows a valid matrix product when passing through the  loop  the
  352. first time.
  353.  
  354.  
  355.  
  356.  
  357.  
  358.                    6
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366. Although this file is not intended as a tutorial on ac circuit theory,
  367. it was  felt  that  some  exposure  was  required.  File  APPENDIX.DOC
  368. presents the circuit interpretations of the Z,Y,S and X matrices.
  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.                    7
  419.  
  420.  
  421.