#lang racket
(require plot
(planet williams/science/math)
(planet williams/science/statistics)
(planet williams/science/fft))
(printf "Multi-Radix Complex FFT~n")
(define data (build-vector 5000 (lambda (t) (+ (sin (* t (/ 2*pi 500))) 0.0))))
(define data-points (for/list ((j (in-vector data))
(i (in-naturals)))
(vector i j)))
(plot (points data-points)
#:title "Data"
#:x-min 0
#:x-max (length data-points)
#:y-min -1.0
#:y-max 1.0)
(fft-complex-forward data)
(define data-max (for/fold ((max-magnitude 0.0))
((x (in-vector data)))
(max (magnitude x) max-magnitude)))
(define data-points-forward (for/list ((j (in-vector data))
(i (in-naturals)))
(vector i (magnitude j))))
(plot (points data-points-forward)
#:title "Complex FFT (Forward)"
#:x-min 0
#:x-max (length data-points-forward)
#:y-max data-max)
(fft-complex-inverse data)
(define data-points-inverse (for/list ((j (in-vector data))
(i (in-naturals)))
(vector i (real-part j))))
(plot (points data-points-inverse)
#:title "Complex FFT (Inverse)"
#:x-min 0
#:x-max (length data-points-inverse)
#:y-min -1.0
#:y-max 1.0)