'* LPFSPICE.txt is here 'de NU2B .....have fun!'
'*
'* The three major BASIC subroutines for calculating
'* actual filter element values are given here.
'*
'* SUB ButCoeff calculates the Butterworth coefficients.
'* SUB TchCoeff calculates the Tchebychev coefficients.
'* SUB CalcElement converts coefficients to ladder elements
'* consisting of series and shunt capacitors and inductors.
'*
DEFINT A-Z
SUB ButCoeff (N%, G!())
'* This sub calculates Butterworth low-pass coefficients normalized to
'* 1 ohm and 1 radian/second where:
'* N% is the filter order
'* PI = 3.14159265
'* G!(0) is the source resistance
'* G!(N%+1) is the load resistance
FOR K = 1 TO N%
G!(K) = 2! * SIN((2! * K - 1) * PI * (1 / (2! * N%)))
NEXT K
G!(0) = 1
G!(N% + 1) = 1
END SUB
DEFINT A-Z
' This sub calculates Lowpass Filter elements from the normalized
' lowpass coefficients after determining source impedance
' and filter cutoff frequency
'
SUB CalcElement (Ro!, Fc!, N%, G!(), Element!())
'* Ro! is source resistance in ohms
'* Fc! is the filter cutoff frequency in Hz
'Change cutoff freq from 1 rad/sec to Wc rad/sec
'Change impedance from 1 ohm to Ro ohms
Wc! = 2 * PI * Fc!
KL! = Ro! / Wc!
KC! = 1 / (Ro! * Wc!)
Element!(0, 1) = Ro! * G!(0) 'RSOURCE
Element!(0, 2) = Ro! * G!(0)
Element!(N% + 1, 1) = Ro! * G!(N% + 1) 'RLOAD
Element!(N% + 1, 2) = Ro! * G!(N% + 1)
''Load element array with capacitors and inductors
'unwind them later
FOR Capnum = 1 TO N%
Element!(Capnum, 1) = KC! * G!(Capnum)
NEXT Capnum
FOR Indnum = 1 TO N%
Element!(Indnum, 2) = KL! * G!(Indnum)
NEXT Indnum
'Now unwind the array to form input"C" or input "L" sections
FOR I = 2 TO N% STEP 2
SWAP Element!(I, 1), Element!(I, 2)
NEXT I
END SUB
DEFINT A-Z
'* This sub calculates Tchebychev low-pass coefficients normalized to
'* 1 ohm and 1 radian/second where:
'* N% is the filter order
'* Amdb! is the passband ripple in dB
'* PI = 3.14159265
'* G!(0) is the source resistance in ohms
'* G!(N%+1) is the load resistance in ohms
SUB TchCoeff (N%, G!(), Amdb!)
Tch:
REM TCH COEFF ARE HERE
REM calculate and load to G!(N+1), i.e., Rout may not = Ro
REM if N is even Rout does not = Ro
INPUT "PEAK PASSBAND RIPPLE DB?", Amdb!
X! = Amdb! / 17.37
X! = EXP(X!)
TANH! = (X! - 1! / X!) / (X! + 1! / X!)
BETA! = LOG(1! / TANH!)
X! = BETA! / (2 * N)
X! = EXP(X!)
SINH! = (X! - 1 / X!) / 2
GAMMA! = SINH!
FOR K = 1 TO N: REM load Ak & Bk
BK!(K) = GAMMA! ^ 2 + SIN(K * PI / N) ^ 2
AK!(K) = SIN((2 * K - 1) * PI * (1 / (2 * N)))
REM test PRINT Bk(K),Ak(K)
NEXT K
REM load G! (K)
G!(1) = 2 * AK!(1) / GAMMA!
FOR K = 2 TO N
G!(K) = 4 * AK!(K - 1) * AK!(K) / (BK!(K - 1) * G!(K - 1))
REM test print G! (K)
NEXT K
REM odd or even N?
X! = N / 2
IF X! - FIX(X!) = 0 THEN
REM N is even
X! = BETA! / 4
X! = EXP(X!)
TANH! = (X! - 1 / X!) / (X! + 1 / X!)
G!(N + 1) = TANH! ^ 2
ELSE
REM N is odd
G!(N + 1) = 1
END IF
G!(0) = 1
END SUB