| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! 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 ;
 | 
					
						
							|  |  |  | IN: math.fft | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-09 17:36:30 -05:00
										 |  |  | : n^v ( n v -- w ) [ ^ ] with map ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : even ( seq -- seq ) 2 group 0 <column> ;
 | 
					
						
							|  |  |  | : odd ( seq -- seq ) 2 group 1 <column> ;
 | 
					
						
							|  |  |  | DEFER: fft | 
					
						
							|  |  |  | : two ( seq -- seq ) fft 2 v/n dup append ;
 | 
					
						
							| 
									
										
										
										
											2007-10-21 17:37:50 -04:00
										 |  |  | : omega ( n -- n ) recip -2 pi i* * * exp ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : 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 ;
 |