# # FFT_Python_1.4.0.py # # Simple FFT for Python Versions 1.4.0 to 3.7.0 on _ALL_ platforms. # # Requirements: # 1) Standard A1200 with HDD, AMIGA OS3.0.x. # 2) Python 1.4.0, full install on AMINET. # 3) This DEMO file, renamed to "FFT_Python_1.4.0.py". # # Checked on: # A stock AMIGA, OS3.0.x using Python 1.4.0 and 2.0.1. # WinUAE and FS-UAE using AMIGA OS3.1x, using Python 1.4.0 and 2.0.1. # A Macbook Pro, OSX 10.13.6, Python, 2.7.x and 3.5.2. # A Windows 10 machine with the current, as of the upload date, Python 3.7.0. # A Linux Mint 19 machine with Python 2.7.x. # # After much searching, different approaches were found and every one didn't # work on Python 1.4.0, and was virtually unmodifyable to suit. # There was ONE however that was, with a little work, modifyable to work from # Python 1.4.0 to 3.7.0 on almost ANY platform. # These variations of code blocks have pointed out to me the limitations of # Python 1.4.0 compared to even Python 2.0.1 for the AMIGA. # Strangely enough it was Public Domain so FULLY CC0 it will remain, and # almost totally impossible to find buried in Google's search facility. # # I TAKE NO CREDIT FOR THE ORIGINAL CODE BLOCK. # I do however return this code back to the Public Domain, CC0 Licence, with # the modifications to run on the lowly Python 1.4.0 that runs on a STOCK # AMIGA 1200(HD), yet still have the ability to work on Python 3.7.0. # # TAKE NOTE: This is the SIMPLEST possible method using zero, [0.0], padding # to powers of 2 and does cause minor problems with the results that are created. # I'll let you do the research as to why... ;o) import cmath def fft(DATA): # DATA points from +1.0 to -1.0 using 0.0 as the _DC_ level padders. N=len(DATA) # Getout if DATA size is less than or equal to 1. if N<=1: return DATA RESULT=[] # For each RESULT list element... for K in range(N): S=complex(0) # For each DATA element... for T in range(N): ANGLE=2j*cmath.pi*T*K/int(N) S=S+(DATA[T]*cmath.exp(-ANGLE)) RESULT.append(S) return RESULT # Padded with trailing 0.0(s) to make up a power of 2 DATA size, (16 samples). 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, 0.0, 0.0, 0.0] # A perfect frequency to power of 2 sample size, (16 samples). #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] # Example code to display a horizontal spectrum display. FFT=fft(FFT_LIST) print(FFT) print("") print("Quick text mode spectrum display...") # Quick text mode spectrum display. for FFT_LISTING in range(0,len(FFT),1): CHAR='*' HORIZ=(4*(int(abs(FFT[FFT_LISTING])))) for DISPLAY in range(1,HORIZ,1): CHAR=CHAR+'*' print(CHAR) # What to expect using this VERY basic FFT program using the enabled "FFT_LIST"... # # [(1+0j), (7.275642373458594-3.8614288110854966j), (-3.4142135623730967-0.9999999999999999j), # (0.10285042102434117-0.4829360166025667j), (3.0000000000000027-1.9999999999999987j), # (-0.34549110814362877+0.9312775457705329j), (-0.5857864376269075+0.9999999999999972j), # (0.9669983136606939-2.4472152487124035j), (1+5.022289837777324e-15j), # (0.9669983136606818+2.447215248712401j), (-0.5857864376268997-1.000000000000009j), # (-0.3454911081436235-0.9312775457705185j), (2.999999999999994+2.000000000000008j), # (0.10285042102433833+0.48293601660255336j), (-3.414213562373087+1.000000000000001j), # (7.275642373458576+3.8614288110855126j)] # # Quick text mode spectrum display... # **** # ******************************** # ************ # * # ************ # * # **** # ******** # **** # ******** # **** # * # ************ # * # ************ # ********************************