There appeared in the December 1990, January 1991, and February 1991 issues of QZX a series of programs to aid in the design of high, low, and bandpass filters. This article will combine these three programs and offer some suggestions to improve them. The relevant circuit diagrams appeared in the January and February issues and some comments on recycling through a given filter design appeared in the January issue. These parts of the series will not be repeated here. The code for the combined program is given below with some comments on the individual lines of code following.
1000 PRINT "ACTIVE FILTER PROGRAM"
1010 PRINT "BASED ON CODE FROM WA3GLW"
1020 PAUSE 100
1030 CLS
1040 PRINT "DESIGN PROGRAM - ACTIVE FILTERS"
1050 PRINT
1060 PRINT
1070 PRINT
1080 PRINT
1090 PRINT "THIS PROGRAM WILL HELP YOU"
1100 PRINT "DESIGN ACTIVE FILTERS"
1110 PRINT
1120 PRINT "THE PROGRAM WILL HELP YOU WITH"
1130 PRINT " 1. HIGH PASS FILTERS"
1140 PRINT " 2. LOW PASS FILTERS"
1150 PRINT " 3. BANDPASS FILTERS'
1160 PRINT
1170 PRINT "ENTER NUMBER OF TYPE DESIRED"
1180 INPUT N
1190 PRINT "YOU SELECTED ";N
1200 PRINT "IF THIS IS CORRECT, ENTER Y"
1210 INPUT Y$
1220 IF Y$ = "Y" THEN GOTO 1300
1230 GOTO 1030
1300 IF N = 1 THEN GOTO 2000
1310 IF N = 2 THEN GOTO 3000
1320 IF N = 3 THEN GOTO 4000
1330 CLS
1340 PRINT "THE NUMBER ENTERED IS NOT USED"
1350 GOTO 1110
2000 CLS
2010 PRINT "HIGH PASS ACTIVE FILTER"
2020 PRINT "THE STAGE GAIN SHOULD BE LESS THAN 10"
2030 PRINT "ENTER STAGE GAIN
2040 INPUT H
2050 PRINT H
2060 PRINT "ENTER CUTOFF FREQ IN HZ"
2070 INPUT F
2080 PRINT F
2090 PRINT "ENTER DAMPING COEFFICIENT. USE"
2100 PRINT "0.707 FOR BUTTERWORTH OR FLAT FILTER"
2110 INPUT Z
2120 PRINT "ENTER INPUT CAP (C2) IN UF"
2130 INPUT C2
2140 PRINT C2
2150 LET C2 = C2/1000000
2160 LET R1 = (2*H+1)/(4*PI*Z*F*C2)
2170 LET R2 = Z/(PI*F*C2*92+1/H))
2180 LET C1 = C2/H
2190 LET C1 = C1*1000000
2200 PRINT "R1 = ";R1;" OHMS"
2210 PRINT "R2 = ";R2;" OHMS"
2220 PRINT "C1 = ";C1;" UF"
2230 PRINT "PRESS 1 TO CONTINUE"
2240 PRINT "ANYTHING ELSE TO STOP"
2250 IF INKEY$ = "" THEN GOTO 2250
2260 LET A$ = INKEY$
2270 IF NOT A$ = "1" THEN STOP
2280 GOTO 1030
3000 CLS
3010 PRINT "LOW PASS ACTIVE FILTER"
3020 PRINT "THE STAGE GAIN SHOULD BE LESS THAN 10"
3030 PRINT "ENTER STAGE GAIN"
3040 INPUT H
3050 PRINT H
3060 PRINT "ENTER CUTOFF FREQ IN HZ"
3070 INPUT F
3080 PRINT F
3090 PRINT "ENTER DAMPING COEFFICIENT. USE"
3100 PRINT "0.707 FOR BUTTERWORTH OR FLAT FILTER"
3110 INPUT Z
3120 PRINT Z
3130 PRINT "ENTER FEEDBACK CAP (C2) IN UF"
3140 INPUT C2
3150 PRINT C2
3160 LET C2 = C2/1000000
3170 LET R2 = Z/(2*PI*F*C2)
3180 LET R3 = R2/(H+1)
3190 LET R1 = R2/H
3200 LET C1 = (1+H)*C2/Z
3210 LET C1 = C1*1000000
3220 PRINT "R1 = ";R1;" OHMS"
3230 PRINT "R2 = ";R2;" OHMS"
3240 PRINT "R3 = ";R2;" OHMS"
3240 PRINT "C1 = ";C1;" UF"
3250 PRINT "PRESS 1 TO CONTINUE"
3260 PRINT "ANYTHING ELSE TO STOP"
3270 IF INKEY$ = "" THEN GOTO 3270
3280 LET A$ = INKEY$
3290 IF NOT A$ = "1" THEN STOP
3300 GOTO 1030
4000 CLS
4010 PRINT "BANDPASS ACTIVE FILTER"
4020 PRINT "THE STAGE GAIN SHOULD BE LESS THAN 10"
4030 PRINT "ENTER STAGE GAIN"
4040 INPUT H
4050 PRINT H
4060 PRINT "ENTER THE CENTER FREQ IN HZ"
4070 INPUT F
4080 PRINT F
4090 LET W = 2*PI*F
4100 PRINT "ENTER THE Q"
4110 INPUT Q
4120 PRINT Q
4130 PRINT "ENTER THE INPUT CAP (C2) IN UF"
4140 INPUT C2
4150 PRINT C2
4160 LET C2 = C2/1000000
4170 PRINT "ENTER FEEDBACK CAP (C1) IN UF
4180 INPUT C1
4190 PRINT C1
4200 LET C1 = C1/1000000
4210 LET R1 = Q/(H*W*C1)
4220 LET T = R1/(Q*(C1+C2)*W)
4230 LET B = R1 - 1/(Q*(C1+C2)*W
4240 LET R2 = T/B
4250 LET R3 = Q*(C2 + C1)/(C1*C1*W)
4260 PRINT "R1 = ";R1;" OHMS"
4270 PRINT "R2 = ";R2;" OHMS"
4280 PRINT "R3 = ";R3;" OHMS"
4290 PRINT "PRESS 1 TO CONTINUE"
4300 PRINT "ANYTHING ELSE TO STOP"
4310 IF INKEY$ = "" THEN GOTO 4290
4320 LET A$ = INKEY$
4330 IF NOT A$ = "1" THEN STOP
4340 GOTO 1030
9998 SAVE "AFILt"
9999 GOTO 10
Some comments on some of the lines are given here. The line numbering itself has had some thought given to it. The beginning line number is 1000 so that all line numbers will have four digits. Thus the spacing will be uniform and not jump by one place as would happen when the line numbers increased from 90 to 100. The line numbers increase by steps of ten so that it will be easy to add lines without the necessity of renumbering as would be the case is the line numbers incresed by only one unit. Each of the three main parts of the program starts with a new thousand to locate the various parts of the program.
Line 1020 Causes the program to display the first two lines for a time which is adjusted by changing the number after PAUSE. It is not important for these lines to be read on the screen. They are intended to identify the code in a listing.
Line 1030 Automatically clears the screen before a choice is offered to you.
Line 1040 The print statement had to be shortened from the original version to keep its length less than the maximum of 32 characters on a line.
Lines 1050 – 1080 These just space the next information down a few lines on the screen for ease of reading.
Line 1190 Note the space after SELECTED, placed there so the screen will look right when the number you selected is printed right after the quoted text according to the ;.
Line 1200 This line does not fully explain what to do if you make a mistake here. But anything other than Y is treated as a no.
Line 1210 The input statement here causes the program to wait for an action on your part. This wait allows you time to read the screen and check your selection.
Lines 1300 – 1320 These lines direct the flow of the program to the correct section.
Lines 1330 – 1350 These lines trap any number not assigned a section and return you to the start of the selection process. Note that the screen is cleared and the program returned to a point that spaces the lines on the screen in a readable fashion.
Lines 2230 – 2280 These lines provide you the choice of ending or starting over again. There are equivalent lines in the 3000 and 4000 sections of the main program. The reasoning behind these lines are given in the January issue of QZX.
There are a lot of things which can still be done with this program. The screen design is almost non-existent. It can be made much more appealing. At the end of each sub-program, you are only given two choices – to end, or to start all over again from the beginning. It would be rather easy to arrange to rum just the sub-program again. Note that, as is the case with many programs, most of the lines have to do with formating the input or output and that the real calculations take up very few lines.
But here one does have a way to combine separate small programs into one large program. This method can be easily applied to other programs which you have or write.