Speaker Enclosure Calc

Date: 1984
Type: Program
Platform(s): TS 2068

This program calculates acoustic parameters for a bass-reflex (ported) speaker enclosure, taking ten user-supplied driver and cabinet measurements as inputs. For each frequency from 15 Hz to 250 Hz in 5 Hz steps, it computes and displays the output power and admittance using a 4×4 matrix determinant solved via a brute-force permutation loop. The determinant subroutine at line 1010 iterates over all combinations of four distinct column indices to evaluate the Leibniz expansion of the determinant, toggling the sign variable `E` to handle the alternating sign. Physical constants embedded in the formulas (e.g., 1.43E6, 3.49E-2, 39.4784) encode relationships between SI units and the acoustic impedance model.


Program Structure

The program is divided into three logical phases. Lines 7–136 handle initialization and user input, collecting ten parameters: coil resistance (RC), mounting compliance (MC), speaker radius (RS), enclosure volume (V), BL product (BL), free resonance (FO), port radius (RP), port length (LP), speaker damping (SD), and port damping (PD). Lines 140–300 precompute the stiffness matrix B and compliance matrix C from the physical parameters. Lines 310–900 form the main frequency sweep loop (48 iterations, 5 Hz steps starting at 15 Hz), building the system matrix A at each frequency and repeatedly calling the determinant subroutine to solve the acoustic circuit equations.

Matrix Determinant Subroutine (Lines 1010–1240)

The subroutine at line 1010 computes the determinant of the 4×4 matrix A using an explicit Leibniz (permutation) expansion. Four nested loops over indices I, J, K, and X enumerate all combinations of four distinct column indices, accumulating the signed product A(1,I)*A(2,J)*A(3,K)*A(4,X) into D. The sign variable E (initialized to 1 at line 10) is toggled by LET E=-E at lines 1195 and 1215 to implement the alternating sign rule. This approach avoids any pivot-based Gaussian elimination, at the cost of evaluating all 4! = 24 terms explicitly.

Cramer’s Rule Application

The main loop applies Cramer’s rule to solve for the velocity components of the acoustic circuit. The determinant of the unmodified matrix is stored as A0. Each subsequent call to the subroutine substitutes a column of A with the forcing vector (derived from IS = BL/RC) and saves the result as A1, A2, A3, and D (for the fourth column). The column is restored from the temporary array T between calls. Velocity components VA, VB, VC, VD are then ratios of the modified determinants to A0.

Frequency Sweep and Output

The frequency sweep runs from 15 Hz to 250 Hz in steps of 5 Hz (48 iterations of the FOR Z=1 TO 48 loop, with F initialized to 10 and incremented by 5 each iteration). At each frequency, three values are printed: frequency F, acoustic output power PS, and cone admittance magnitude IM. Power is computed as:

  • P = 3.49E-2 * F^2 * RS^4 (radiation resistance factor)
  • PS = P * ((VA+VC)^2 + (VB+VD)^2) (total radiated power combining real and imaginary velocity components)

Admittance IM is the magnitude of the cone current divided by BL, computed as SQR(IA*IA + IB*IB)/BL.

Bugs and Anomalies

  • Lines 760–770: Both VA and VB are assigned A1/A0, making them identical. VB should almost certainly be A2/A0 to represent the imaginary component of the first velocity. This is likely a transcription error from the original magazine listing.
  • Line 700: The loop reads FOR I=I TO 4 instead of FOR I=1 TO 4. Since I retains the value 4 from the previous loop exit, this loop executes only once (for I=4), meaning A(1,4), A(2,4), and A(3,4) are not zeroed before the fourth determinant call. This is almost certainly a typo for FOR I=1 TO 4.
  • Sign toggling logic: The placement of LET E=-E at line 1215 (inside the J loop but outside the K loop) interacts with the toggling at line 1195 (inside the X loop). The global state of E persists across subroutine calls since E is never reset inside the subroutine. Because there are exactly 24 sign toggles per complete determinant evaluation (an even number), E returns to its entry value after each full call, but this relies on all loops completing without early exits — the GO TO skips do affect the toggle count and the correctness of the sign sequence is non-obvious.
  • Line 150: The constant 39.47818 is used here but 39.4784 is used at line 420 — a minor inconsistency likely from manual transcription.

Key BASIC Idioms

  • Use of 2* PI*F for angular frequency ω throughout the matrix construction.
  • Column save/restore via the temporary array T(4) to implement Cramer’s rule without a separate matrix copy.
  • Physical embedded constants (e.g., 1.43E6, 0.219) fold unit conversions and π factors into single numeric literals.

Image Gallery

Source Code

    4 REM submitted by Ronald    Ginardi to TTSUC 5/2/90
    5 REM This listing was copied from some electronics magazine  some time back. I was unable to locate where I got it earlier   this year when I attempted to   use it to design an enclosure
    6 REM I did not include      default values when typing it in(or directions for that matter)
    7 INK 0:PAPER 7:BORDER 7:CLS 
    8 PRINT AT 8,1;"SPEAKER ENCLOSURE CALCULATOR"
   10 DIM G(4,4):DIM C(4,4):LET E=1
   20 DIM B(4,4):DIM A(4,4):DIM T(4)
   60 INPUT "COIL RESISTANCE = ";RC
   70 INPUT "MOUNTING COMPLIANCE = ";MC
   80 INPUT "SPEAKER RADIUS = ";RS
   90 INPUT "ENCL VOLUME = ";V
  100 INPUT "BL PRODUCT = ";BL
  110 INPUT "FREE RESONANCE = ";FO
  120 INPUT "PORT RADIUS = ";RP
  130 INPUT "PORT LENGTH = ";LP
  134 INPUT "SPEAKER DAMPING = ";SD
  136 INPUT "PORT DAMPING = ";PD
  140 LET B1=1/MC
  150 LET C1=B1/(39.47818*FO*FO)
  160 LET B2=1.43E6*RS*RS*RS*RS/V
  170 LET C2=(3.83*LP+5.69*RP)*RS*RS*RS*RS/(RP*RP)
  180 LET B(1,1)=-(B1+B2)
  190 LET B(1,3)=B2
  200 LET B(2,2)=-(B1+B2)
  210 LET B(2,4)=B2
  220 LET B(3,1)=B2
  230 LET B(3,3)=-B2
  240 LET B(4,2)=B2
  250 LET B(4,4)=-B2
  260 LET C(1,1)=C1
  270 LET C(2,2)=C1
  280 LET C(3,3)=C2
  290 LET C(4,4)=C2
  300 LET IS=BL/RC
  305 PRINT "FREQ"; TAB 9;"POWER"; TAB 20;"ADMIT."
  310 LET F=10
  320 FOR Z=1 TO 48
  330 LET F=F+5
  340 LET G0=.219*F*F*RS*RS*RS*RS
  350 LET G1=G0+BL*BL/RC+SD
  360 LET G(1,2)=G1
  370 LET G(2,1)=-G1
  375 LET G2=G0+PD
  380 LET G(3,4)=G2
  390 LET G(4,3)=-G2
  400 FOR I=1 TO 4
  410 FOR J=1 TO 4
  420 LET A(I,J)=39.4784*F*F*C(I,J)+2* PI*F*G(I,J)+B(I,J)
  430 NEXT J
  440 NEXT I
  450 GO SUB 1010
  460 LET A0=D
  470 FOR I=1 TO 4
  480 LET T(I)=A(I,1)
  490 LET A(I,1)=0
  500 NEXT I
  510 LET A(2,1)=2* PI*F*IS
  520 GO SUB 1010
  530 LET A1=D
  540 FOR I=1 TO 4
  550 LET A(I,1)=T(I)
  560 LET T(I)=A(I,2)
  570 LET A(I,2)=0
  580 NEXT I
  590 LET A(2,2)=-2* PI*F*IS
  600 GO SUB 1010
  610 LET A2=D
  620 FOR I=1 TO 4
  630 LET A(I,2)=T(I)
  640 LET T(I)=A(I,3)
  650 LET A(I,3)=0
  660 NEXT I
  670 LET A(2,3)=-2* PI*F*IS
  680 GO SUB 1010
  690 LET A3=D
  700 FOR I=I TO 4
  710 LET A(I,3)=T(I)
  720 LET A(I,4)=0
  730 NEXT I
  740 LET A(2,4)=-2* PI*F*IS
  750 GO SUB 1010
  760 LET VA=A1/A0
  770 LET VB=A1/A0
  780 LET VC=-A3/A0
  790 LET VD=-D/A0
  792 LET IA=IS-VA*BL*BL/RC
  794 LET IB=-VB*BL*BL/RC
  796 LET IM= SQR (IA*IA+IB*IB)/BL
  800 LET P=3.49E-2*(F^2*RS^4)
  810 LET PS=P*((VA+VC)*(VA+VC)+(VB+VD)*(VB+VD))
  880 PRINT F; TAB 6;PS; TAB 20;IM
  900 NEXT Z
  910 STOP 
 1010 LET D=0
 1020 FOR I=1 TO 4
 1030 FOR J=1 TO 4
 1040 IF J=I THEN GO TO 1220
 1050 FOR K=1 TO 4
 1060 IF K=I THEN GO TO 1210
 1070 IF K=J THEN GO TO 1210
 1080 FOR X=1 TO 4
 1090 IF X=I THEN GO TO 1200
 1100 IF X=J THEN GO TO 1200
 1110 IF X=K THEN GO TO 1200
 1190 LET D=D+E*A(1,I)*A(2,J)*A(3,K)*A(4,X)
 1195 LET E=-E
 1200 NEXT X
 1210 NEXT K
 1215 LET E=-E
 1220 NEXT J
 1230 NEXT I
 1240 RETURN 
 9900 REM

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.