%%HP: T(3)A(R)F(.);
@ FFTPLOT by Frank Gregory Baird
DIR
  FFT
    \<<
      IFERR RCLF RAD -15 CF -16 CF \-> x fwd flg
        \<< x SIZE 1 GET DUP LN 2 LN / 0 RND \-> n m
          \<< n 2 / 1 \-> n2 j
            \<< 1 n 1 -
              FOR i
		IF 'i<j'
		THEN x j GET \-> t
		  \<< 'x' j x i GET PUT 'x' i t PUT
		  \>>
		END n2 \-> k
		\<<
		  WHILE 'k<j'
		  REPEAT 'j' k STO- 'k' 2 STO/
		  END 'j' k STO+
		\>>
              NEXT
            \>> 1 m
            FOR l 2 l ^ DUP 2 / \-> le le1
              \<< (1,0) '\pi/le1' \->NUM DUP COS SWAP SIN NEG fwd * R\->C \-> u w
		\<< 1 le1
		  FOR j j n
		    FOR i i le1 + \-> ip
		      \<< x ip GET u * \-> t
		        \<< 'x' ip x i GET t - PUT 'x' i x i GET t + PUT
		        \>>
		      \>> le
		    STEP 'u' w STO*
		  NEXT
		\>>
              \>>
            NEXT
            IF 'fwd==-1'
            THEN 1 n
              FOR i 'x' i x i GET n / PUT
              NEXT
            END
          \>> x flg STOF
        \>>
      THEN CLLCD
"Enter a 2^N
complex vector then
1 for a forward FFT or
-1 for a backward FFT" 3 DISP 2 FREEZE
      END
    \>>
  PLFFT
    \<<
      IFERR CL\GS \-> x
        \<< 1 x SIZE 1 GET
          FOR i x i GET ABS \GS+
          NEXT 1 XCOL BARPLOT GRAPH { \GSDAT \GSPAR } PURGE
        \>>
      THEN
"Enter a 2^N
complex vector" CLLCD 3 DISP 2 FREEZE
      END
    \>>
END
