Fast Fourier transform: Difference between revisions

Line 1,473:
=={{header|lambdatalk}}==
<lang scheme>
 
From a code written by Prasenjit Saha in https://www.physik.uzh.ch/~psaha/mus/fourlisp.php]] we build the FFT using lists.
 
1) the function fft
 
{def fft
{lambda {:s :fx}
{if {= {list.length :fx} 1}
then :fx
else {combinelet :s{ {fft :s {evens :f}s}
{:ev {fft :s {oddsevens :f}x}} }}}
{list.map:od Csub{fft :as {odds :bx}} } }
 
{let { {:ev :ev} {:t {rotate :s {+ :kod 1} :N0 {cdrlist.length :f}}od}}} }
{def combine
{lambdalist.append {:slist.map Cadd :ev :odt}
{plusminus :ev {rotate :s 0 {list.lengthmap Csub :od}ev :odt}} }}}}}
 
{def plusminus
{lambda {:a :b}
{list.append {list.map Cadd :a :b}
{list.map Csub :a :b}}}}
 
{def rotate
{lambda {:s :kf :Nk :fN}
{if {list.null? :f}
then nil
else {cons {Cmul {car :f} {Cexp {Cnew 0 {/ {* :s {PI} :k} :N}}}}
{Cexprotate {Cnew 0 {/:s {*cdr :sf} {PI}+ :k 1} :N}}}}}
{rotate :s {+ :k 1} :N {cdr :f}}}}}}
 
2) functions for lists