KEY 15, CHR$(0) + CHR$(&H2D) ON KEY(15) GOSUB terminate KEY(15) ON DIM tata(8192), x(4096) REM to put in scaling constant (sc), sample rate (sr), and number ' of points (fft) which can be 256, 512, 1024, 2048, or 4096 max sc = .002 sr = .362 fft = 4096 redo: CLS REM this loop clears previous plots FOR i = 1 TO 23 LOCATE i, 1 PRINT " " NEXT i CLOSE #1 SCREEN 9 COLOR 7, 1 LOCATE 1, 1 PRINT "input text file name" INPUT file$ OPEN file$ FOR INPUT AS #1 nn = fft FOR i = 1 TO n tata(i) = 0: NEXT FOR i = 1 TO nn INPUT #1, x(i) sy = sy + x(i) sx = sx + i sx2 = sx2 + i ^ 2 sxy = sxy + i * x(i) NEXT i nn = fft n = 2 * nn CLS a1d = sx2 - sx ^ 2 / nn a1n = sxy - sx * sy / nn a1 = a1n / a1d a0 = sy / nn - a1 * sx / nn FOR i = 0 TO nn - 1 x(i) = x(i) - a1 * i - a0 NEXT i FOR j = 2 TO n STEP 2 tata(j - 1) = x(j / 2) NEXT j VIEW (150, 40)-(600, 320), , 1 CLS LOCATE 23, 40: PRINT "time" WINDOW (1, -10)-(nn, 10) FOR i = 1 TO nn IF i > 1 THEN LINE (ip, sc * xp)-(i, sc * x(i)) ip = i: xp = x(ip) NEXT SLEEP 2 j = 1 FOR i = 1 TO n STEP 2 IF j > i THEN tempr = tata(j) tempi = tata(j + 1) tata(j) = tata(i) tata(j + 1) = tata(i + 1) tata(i) = tempr tata(i + 1) = tempi END IF m = n / 2 SET1: IF m >= 2 AND j > m THEN j = j - m m = m / 2 GOTO SET1 END IF j = j + m NEXT i mmax = 2 SET2: IF n > mmax THEN istep = 2 * mmax theta = 6.28318530717959# / mmax wpr = -2! * SIN(.5 * theta) ^ 2 wpi = SIN(theta) wr = 1! wi = 0! FOR m = 1 TO mmax STEP 2 FOR i = m TO n STEP istep j = i + mmax tempr = wr * tata(j) - wi * tata(j + 1) tempi = wr * tata(j + 1) + wi * tata(j) tata(j) = tata(i) - tempr tata(j + 1) = tata(i + 1) - tempi tata(i) = tata(i) + tempr tata(i + 1) = tata(i + 1) + tempi NEXT i wtemp = wr wr = wr * wpr - wi * wpi + wr wi = wi * wpr + wtemp * wpi + wi NEXT m mmax = istep GOTO SET2 END IF '''''''''''''''''''''''''''''' SECONDLOOP: CLS VIEW (150, 40)-(600, 320), , 1 WINDOW (1, -140)-(nn, 20) FOR i = 2 TO nn STEP 2 ta = sc ^ 2 * (tata(i) ^ 2 + tata(i - 1) ^ 2) / (nn / 2) ^ 2 db = 10 * .4343 * LOG(ta): ' .4343 to convert from natural log to base 10 log IF i > 2 THEN LINE (ip, dbp)-(i, db) ip = i: dbp = db PSET (10 * i, 20) PSET (10 * i, 0) PSET (10 * i, -20) PSET (10 * i, -40) PSET (10 * i, -60) PSET (10 * i, -80) PSET (10 * i, -100) PSET (10 * i, -120) NEXT LOCATE 11, 1 PRINT " dB " LOCATE 7, 35: PRINT "SPECTRUM ("; fft; "point FFT )" LOCATE 3, 33 PRINT "Frequency (frac. of"; sr / 2; "Hz)" LOCATE 3, 17: PRINT "20" LOCATE 8, 16: PRINT "-20" LOCATE 13, 16: PRINT "-60" LOCATE 18, 15: PRINT "-100" LOCATE 23, 15: PRINT "-140" LOCATE 2, 29: PRINT "0.2" LOCATE 2, 41: PRINT "0.4" LOCATE 2, 52: PRINT "0.6" LOCATE 2, 64: PRINT "0.8" LOCATE 2, 76: PRINT "1." CLOSE #1 waitps: IF INKEY$ = "r" THEN GOTO redo GOTO waitps: terminate: END