FFT for the AMIGA through ksh88 shell.

I don't know if anyone is interested but I have been meddling with FFT for the AMIGA.
(Sadly we AMIGAns don't have these luxuries through any scripting language.
Below is a Python snippet that uses the builtin 'cmath' module to work with the lowly
Python 2.0.1 for the AMIGA. It is part of a greater script that is a KSH shell script.

To get all of this working was not easy.

The image is OSX 10.13.0 running the AMIGA emulator, FS-UAE, booting into a window,
(purely for this upload, I normally use full-screen mode), of my A1200 setup. From the
default AMIGA shell, ADE, the UNIX emulator, is run up with KSH88 running on top of the
AMIGA shell. There is a KSH shell script launched that creates this Python code on the fly,
launches python and the code, and the spectrum of a 2 cycle, 64 sample square wave is
produced and then plotted to this window.

The Python code actually works on the default python 2.7.x in OSX 10.13.0 also but does
not work in Python 3.x.x at all as it was primarily aimed at Python 2.0.1.

# Python 2.0 (#1, Oct 29 2000, 23:53:20)  (SAS/C 6.x] on amiga
# Type "copyright", "credits" or "license" for more information.

# The line below is for progress info ONLY.
print("\033[23;1fNow running the Python FFT function...")

import sys
import cmath
def fft(DATA):
        N=len(DATA)
        if N<=1: return DATA
        EVEN=fft([DATA[K] for K in range(0,N,2)])
        ODD=fft([DATA[K] for K in range(1,N,2)])
        L=[EVEN[K]+cmath.exp(-2j*cmath.pi*K/N)*ODD[K] for K in range(N/2)]
        R=[EVEN[K]-cmath.exp(-2j*cmath.pi*K/N)*ODD[K] for K in range(N/2)]
        return L+R

FFT_LIST=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,\
 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,\
 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0,\
 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

FFT=fft(FFT_LIST)
# print(FFT)
LENGTH=len(FFT)
STDOUT=sys.stdout
sys.stdout=open("DATA.txt", "w")
for FFT_LISTING in range(0,LENGTH,1): print("%i" % (int(abs(FFT[FFT_LISTING]))))
sys.stdout=STDOUT
sys.exit()

Have fun...

1 Like