home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
- COMPLEX MATH SUBROUTINES FOR CBASIC
-
- by
-
- E.R. LE CLEAR
-
- 10/12/1980
-
- This file describes a method for storing and using CBASIC "public
- library" subroutines as well as providing listings for specific
- complex math routines. In order to illustrate the general use of these
- subroutines, program LPFILTAN.BAS is provided which can be used to
- predict the input impedance and voltage transfer characteristics of
- multiple low pass filters.
-
- ***** THE PUBLIC LIBRARY *****
-
- Since CBASIC does not normally use line numbers, the numeric lables
- required to identify program transfer statement entry can occur
- anywhere in the program and in any order. This allows programs to be
- written and reference predefined "line numbers" which define
- subprograms that can be appended to the main program prior to
- compilation. These subprograms are maintained on the disk as a library
- of files that can be concantenated to the main program. For instance,
- suppose that main program file NETWORK.TMP has been written which uses
- subroutines REC/POL and POL/REC. A CBASIC source file is then
- generated as follows:
-
-
- PIP NETWORK.BAS=NETWORK.TMP,REC/POL.SRT,POL/REC.SRT
-
-
- The program file NETWORK.BAS now includes all three files concatenated
- to form a single program file which is ready to compile and run. Note:
- all of the library subroutine file headings are of the format
- XXXXXX.SRT .
-
- ***** COMPLEX MATH SUBROUTINES *****
-
- Basic cannot handle complex math expressions directly. It is usually
- necessary to carry the real and imaginary parts through the program
- separately. For instance, in order to add two complex quantities
- (A=B+C), the following program segments might be used:
-
- BR=WWWW REAL PART OF B
- BI=XXXX IMAGINARY PART OF B
- CR=YYYY REAL PART OF C
- CI=ZZZZ IMAGINARY PART OF C
- AR=BR+CR REAL PART OF A
-
-
- 1
-
-
-
-
-
-
-
-
- AI=BI+CI IMAGINARY PART OF A
-
- IE. (AR+JAI)=(BR+JBI)+(CR+JCI)
-
- ADDITION and subtraction are straightforward and are usually simpler
- TO do in line as they are required. Complex multiplication, division
- and other functions become quite tedious to handle and are prime
- candidates for subroutine implementation.
-
-
- File DISK.DOC is the documentation file for the author's CBASIC
- complex math disk. This File is used to provide documentation of the
- disk programs. Removing documentation from individual subroutine files
- and accumulating them in a separate documentation file minimizes the
- length of the final source file while a printout provides a handy
- reference while writing new programs. A brief description of each
- subroutine is provided including the "line number" of the subroutine
- and a definition of the input and output variable formats.
-
-
- When a subroutine is used, the appropriate variables must be renamed
- to that of the input variable required by the subroutine. In the same
- manner, output variables must be renamed if the data is to be saved
- for future use. Many times, the current output variable can be used
- immediately by the next subroutine without renaming the variables.
-
-
- The most commonly used subroutines will be 100.00 through 104.100. It
- is almost impossible to do even the simplest ac circuit analysis
- without using one of these.
-
-
- Subroutines 105.100 and 106.100 will be useful in certain microwave
- engineering calculations while subroutines 107.100 through 111.100 are
- used in advanced circuit analysis using matrix algebra.
-
-
- Routines 107.100 through 110.100 provide means to change from one
- matrix type to another. These types are:
-
- S SCATTERING MATRIX
- X TRANSMISSION MATRIX
- Z IMPEDANCE MATRIX
- Y ADMITTANCE MATRIX
-
- A brief discussion on the relationships between the different matrices
- is provided in appendix A.
-
-
-
-
- 2
-
-
-
-
-
-
-
-
- Subroutine 111.100 provides the means for multiplying matrices
- (primarily x matrices). Matrices must be multiplied in the correct
- direction or errors will result.
-
- ***** APPLICATION PROGRAM *****
-
- File LPFILTAN.BAS is a program for predicting the characteristics of
- low pass filters with up to 10 sections of the following type:
-
- ---<LA >---<RLA>---
- 1 1
- O--------<CA >---<RCA>--------O
- 1
- <RB >
- 1
- <LB >
- 1
- <CB >
- 1
- O-----------------------------O
-
- The number of sections is limited by the first DIM statement. The
- value can be changed but 10 sections is more than adaquate to handle
- any practical filter.
-
-
- The program will first ask for the number of sections (N), generator
- source resistance (RG) and load (RL). After entering these, the
- program will request values for each component in each section.
- Entering a "-" response results in the following:
-
- COMPONENT VALUE AUTOMATICALLY ENTERED
- --------- ---------------------------
- LA,CB 1E+15
- ALL OTHERS 1E-15
-
- Any value other than "-" will be entered directly.
-
- After entering all component data, the program will ask whether a hard
- copy is desired. Any response other than "Y" will cause the printout
- to be directed to the console.
-
-
- The program will next ask for the minimum and maximum frequencies and
- the number of frequency points to be calculated. These points will be
- distributed in a logrithmic manner so that data can be plotted on a
- LIN-LOG graph with physically equal spacing.
-
-
-
-
- 3
-
-
-
-
-
-
-
-
- After calculating and printing the results at all of the desired
- frequencies, the program will ask if you want to run a new frequency
- plot with the same part values (F), rerun the whole program with new
- values and frequency parameters (P) or quit (Q).
-
-
- The following dialog shows the evaluation of a six section eliptic
- filter. This particular filter is a low pass prototype. Prototype
- filters are normalized to RG=RL=1 and a cutoff frequency of 1
- RADIAN/SEC (.1592 HERTZ).
-
-
- Program run to evaluate pass band
- A>CRUN2 B:LPFILTAN
-
- CRUN VER 2.05
- LOW PASS FILTERS
- NUMBER OF SECTIONS ? 6
- RG,RL ? 1,1
- TYPE IN SECTION PARAMETERS. TYPE - IF ELEMENT NOT USED
- FOR SHORTED SERIES ARM, SET RB=1E+15
- FOR OPEN SHUNT ARM, SET RB=1E+15
- LA,RLA FOR SECTION 1 ? 1.323,-
- CA,RCA FOR SECTION 1 ? .0833,-
- RB,LB,CB FOR SECTION 1 ? -,-,1.284
- LA,RLA FOR SECTION 2 ? 1.011,-
- CA,RCA FOR SECTION 2 ? .5563,-
- RB,LB,CB FOR SECTION 2 ? -,-,1.807
- LA,RLA FOR SECTION 3 ? .7551,-
- CA,RCA FOR SECTION 3 ? 1.004,-
- RB,LB,CB FOR SECTION 3 ?-,-,1.337
- LA,RLA FOR SECTION 4 ? .8300,-
- CA,RCA FOR SECTION 4 ? .8402,-
- RB,LB,CB FOR SECTION 4 ? -,-,1.204
- LA,RLA FOR SECTION 5 ? 1.088,-
- CA,RCA FOR SECTION 5 ? .3188,-
- RB,LB,CB FOR SECTION 5 ? -,-,1.516
- LA,RLA FOR SECTION 6 ? 0,0
- CA,RCA FOR SECTION 6 ?-,-
- RB,LB,CB FOR SECTION 6 ? -,-,1.087
- HARD COPY ? (Y OR N) Y
-
- LOW PASS FILTER ANALYSIS
-
- FILTER CONSTANTS
-
- RG= 1
- RL= 1
-
-
-
- 4
-
-
-
-
-
-
-
-
- LA 1 = 1.323 RLA 1 = 1E-15
- CA 1 = 0.0833 RCA 1 = 1E-15
- RB 1 = 1E-15 LB 1 = 1E-15 CB 1 = 1.284
-
- LA 2 = 1.011 RLA 2 = 1E-15
- CA 2 = 0.5563 RCA 2 = 1E-15
- RB 2 = 1E-15 LB 2 = 1E-15 CB 2 =1.807
-
- LA 3 = 0.7751 RLA 3 = 1E-15
- CA 3 = 1.004 RCA 3 = 1E-15
- RB 3 = 1E-15 LB 3 = 1E-15 CB 3 = 1.337
-
- LA 4 = 0.83 RLA 4 = 1E-15
- CA 4 = 0.8402 RCA 4 = 1E-15
- RB 4 =1E-15 LB 4 = 1E-15 CB 4 =1.204
-
- LA 5 = 1.088 RLA 5 = 1E-15
- CA 5 = 0.3188 RCA 5 = 1E-15
- RB 5 = 1E-15 LB 5 =1E-15 CB 5 =1.516
-
- LA 6 = 0 RLA 6 = 0
- CA 6 = 1E-15 RCA 6 = 1E-15
- RB 6 = 1E-15 LB 6 = 1E-15 CB 6 = 1.087
-
- FMIN,FMAX ? .01592,.1592
- NUMBER OF DATA POINTS ? 20
- FREQ ALPHA(DB) ANG(ALPHA) ZIN ANG(ZIN)
- ---------------------------------------------------------------------
- 1.592E-02 -0.09 -37.70 8.401E-01 -13.09
- 1.797E-02 -0.11 -42.50 8.101E-01 -13.39
- 2.029E-02 -0.13 -47.91 7.779E-01 -13.26
- 2.290E-02 -0.15 -54.00 7.451E-01 -12.53
- 2.585E-02 -0.16 -60.86 7.142E-01 -11.03
- 2.918E-02 -0.18 -68.63 6.890E-01 -8.58
- 3.294E-02 -0.18 -77.44 6.751E-01 -5.16
- 3.718E-02 -0.16 -87.51 6.798E-01 -1.00
- 4.198E-02 -0.13 80.92 7.123E-01 3.16
- 4.738E-02 -0.08 67.49 7.809E-01 5.93
- 5.349E-02 -0.03 51.78 8.861E-01 5.46
- 6.038E-02 -0.00 33.37 9.996E-01 0.03
- 6.816E-02 -0.03 11.87 1.037E 00 -9.91
- 7.694E-02 -0.12 -13.08 9.289E-01 -18.59
- 8.685E-02 -0.18 -42.34 7.677E-01 -17.12
- 9.804E-02 -0.08 -78.54 7.693E-01 -3.15
- 1.107E-01 -0.02 53.78 1.101E 00 -4.15
- 1.249E-01 -0.18 -9.02 9.403E-01 -22.22
- 1.410E-01 -0.08 73.88 1.294E 00 -4.34
- 1.592E-01 -0.22 26.99 8.275E-01 22.50
-
-
-
- 5
-
-
-
-
-
-
-
-
-
- PROGRAM RUN TO EVALUATE STOP BAND
-
- NEW FREQ PLOT(F), NEW PARAMETERS(P) OR QUIT(Q) F
- FMIN,FMAX ? .1592,..3184
- NUMBER OF DATA POINTS ? 20
- FREQ ALPHA(DB) ANG(ALPHA) ZIN ANG(ZIN)
- ----------------------------------------------------------------------
- 1.592E-01 -0.22 26.99 8.275E-01 22.50
- 1.651E-01 -20.72 83.71 1.815E 01 -87.78
- 1.712E-01 -41.30 51.20 2.840E 00 -90.00
- 1.776E-01 -63.29 33.29 1.853E 00 -90.00
- 1.842E-01 -91.06 20.83 1.450E 00 -90.00
- 1.911E-01 -108.44 11.27 1.219E 00 -90.00
- 1.982E-01 -89.51 3.52 1.063E 00 -90.00
- 2.055E-01 -93.28 -2.99 9.488E-01 -90.00
- 2.132E-01 -110.71 -8.60 8.599E-01 -90.00
- 2.211E-01 -92.85 -13.52 7.878E-01 -90.00
- 2.293E-01 -89.74 -17.90 7.277E-01 -90.00
- 2.378E-01 -89.63 -21.84 6.764E-01 -90.00
- 2.466E-01 -91.43 -25.41 6.319E-01 -90.00
- 2.558E-01 -95.44 -28.68 5.927E-01 -90.00
- 2.653E-01 -104.97 -31.69 5.578E-01 -90.00
- 2.752E-01 -105.49 -34.47 5.264E-01 -90.00
- 2.854E-01 -96.52 -37.05 4.979E-01 -90.00
- 2.960E-01 -92.90 -39.45 4.720E-01 -90.00
- 3.070E-01 -90.97 -41.71 4.482E-01 -90.00
- 3.184E-01 -89.93 -43.82 4.262E-01 -90.00
-
-
- NEW FREQ PLOT(F), NEW PARAMETERS(P) OR QUIT(Q) Q
-
- A>
-
-
-
-
- It should be pointed out that the program utilizes the X parameter
- matrix to calculate the overall filter characteristics rather than an
- elaborate ladder network representation. This results in a simpler and
- shorter program. In addition,the program can be easily modified for
- other types of filter sections without a major rewrite (ie. hi-pass,
- bandpass and bandstop). In order to simplify programming, a unit
- matrix is defined prior to entering the matrix multiplication loop.
- This allows a valid matrix product when passing through the loop the
- first time.
-
-
-
-
-
- 6
-
-
-
-
-
-
-
- Although this file is not intended as a tutorial on ac circuit theory,
- it was felt that some exposure was required. File APPENDIX.DOC
- presents the circuit interpretations of the Z,Y,S and X matrices.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 7
-
-
-