Fast Fourier transform: Difference between revisions
Content deleted Content added
Line 1,474:
<lang scheme>
See http://lambdaway.free.fr/lambdaspeech/?view=lispology4 for more details▼
▲1) the Cfft function (direct & inverse)
{if {= {list.length :f} 1}
then :f
else {combine :s {fft :s {evens :f}}
{def
{lambda {:
{
{def
{lambda {:
{
{def
{lambda {
{
then nil
else
{rotate :s {+ :k
▲{def CUroot
{lambda {:s :od :k :N}▼
We add to the existing {lambda talk}'s list primitives a small set of functions required by the function fft.
▲2) four functions on arrays
{def
{lambda {:
{if {list.null? :l}
{#.new {map {{lambda {:x :i} {#.get :x :i}} :x}▼
then nil
else {cons {car :l} {evens {cdr {cdr :l}}}}}}}
{def
{lambda {:
{if {list.null? {cdr :l}}
then nil
▲ {serie 1 {#.length :x} 2}}} }}
else {cons {car {cdr :l}} {odds {cdr {cdr :l}}}}}}}
{def
{def list.map.r
▲ {lambda {:x}
then :c
else {list.map.r :f {cdr :a} {cdr :b}
{list.map.r :f {list.reverse :a} {list.reverse :b} nil}}}
{def
{def list.append.r
{lambda {:a}▼
{
{if {list.null? :b}
then :a
else {list.append.r {cons {car :b} :a} {cdr :b}}}}}
{lambda {:a :b}
{list.append.r :b {list.reverse :a}} }}
3)
{lambda talk} has no primitive functions working on complex numbers. We add the minimal set required by the function fft.
{def Cnew
Line 1,552 ⟶ 1,564:
{def Cexp
{cons {* {exp {car :x}} {cos {cdr :x}}}
{* {exp {car :x}} {sin {cdr :x}}}} }}
{def Clist
4) testing
Applying the fft function on such a sample (1 1 1 1 0 0 0 0) where numbers have been promoted as complex
{
[(4 0),▼
(1 -2.414213562373095),▼
(0 0),▼
(1 -0.4142135623730949),▼
(0 0),▼
(0.9999999999999999 0.4142135623730949),▼
(0 0),▼
(0.9999999999999997 2.414213562373095)]▼
▲
</lang>
|