From 2fafae50132d4682ada799a9314b59a100272572 Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Fri, 7 Nov 2008 01:35:17 -0500 Subject: [PATCH] Refactor and clean up of math.fft --- extra/math/fft/fft.factor | 43 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/extra/math/fft/fft.factor b/extra/math/fft/fft.factor index b82ecb6b2c..7dfdc0bcfc 100644 --- a/extra/math/fft/fft.factor +++ b/extra/math/fft/fft.factor @@ -1,15 +1,38 @@ -! Fast Fourier Transform, copyright (C) 2007 Hans Schmid -! http://dressguardmeister.blogspot.com/2007/01/fft.html -USING: arrays sequences math math.vectors math.constants -math.functions kernel splitting grouping columns ; +! Copyright (c) 2007 Hans Schmid. +! See http://factorcode.org/license.txt for BSD license. +USING: columns grouping kernel math math.constants math.functions math.vectors + sequences ; IN: math.fft +! Fast Fourier Transform + + + +DEFER: fft + +: two ( seq -- seq ) + fft 2 v/n dup append ; + + ; : odd ( seq -- seq ) 2 group 1 ; -DEFER: fft -: two ( seq -- seq ) fft 2 v/n dup append ; -: omega ( n -- n' ) recip -2 pi i* * * exp ; -: twiddle ( seq -- seq ) dup length dup omega swap n^v v* ; -: (fft) ( seq -- seq ) dup odd two twiddle swap even two v+ ; -: fft ( seq -- seq ) dup length 1 = [ (fft) ] unless ; + +: (fft) ( seq -- seq ) + [ odd two twiddle ] [ even two ] bi v+ ; + +PRIVATE> + +: fft ( seq -- seq ) + dup length 1 = [ (fft) ] unless ; +