I'd like to use the FFT and iFFT functions shown on the dfns page. When I try to run the FFT example there, I get the following:
x←9 3 5 8 1 0 5
y←6 2 2 7 4
x
9 3 5 8 1 0 5
y
6 2 3 7 4
FFT 16↑x
RANK ERROR: Invalid axis
floop[0] floop←{(⊣/⍺)∇⍣(×m)⊢(+⌿⍵),[m-0.5]⍺×[⍳m←≢⍴⍺]-⌿⍵}
∧
FFT 16↑y
RANK ERROR: Invalid axis
floop[0] floop←{(⊣/⍺)∇⍣(×m)⊢(+⌿⍵),[m-0.5]⍺×[⍳m←≢⍴⍺]-⌿⍵}
something wrong with dfns FFT
- Adam|Dyalog
- Posts: 143
- Joined: Thu Jun 25, 2015 1:13 pm
Re: something wrong with dfns FFT
For performance, may want to look into our Math namespace, which you can find at https://github.com/Dyalog/Math/releases.
Re: something wrong with dfns FFT
Thanks! The Math namespace is great; however, I really wanted to see FFT/iFFT implemented in Dyalog (and also to understand why the code in dfns.dws doesn't work). Performance considerations are secondary for me at this point.
Re: something wrong with dfns FFT
This is weird: FFT and iFFT work inside xtimes, but give an error when used alone, e.g.
x
1 2 3 4 5
y
2 3 4 5 6
x xtimes y ⍝ xtimes gives a numeric result, not an error:
2 8 9 5 6 4 3 2 0
12345 × 23456 ⍝ Ordinary multiplication gives the corresponding result:
289564320
FFT¨x extend y ⍝ This subexpression from xtimes generates an error:
RANK ERROR: Invalid axis
floop[0] floop←{(⊣/⍺)∇⍣(×m)⊢(+⌿⍵),[m-0.5]⍺×[⍳m←≢⍴⍺]-⌿⍵}
roots←{×\1,1↓(⍵÷2)⍴¯1*2÷⍵}
cube←{⍵⍴⍨2⍴⍨2⍟⍴⍵}
extend←{(2*⌈2⍟¯1+(⍴⍺)+⍴⍵)↑¨⍺ ⍵}
floop←{(⊣/⍺)∇⍣(×m)⊢(+⌿⍵),[m-0.5]⍺×[⍳m←≢⍴⍺]-⌿⍵}
FFT←{,(cube roots⍴⍵)floop cube ⍵}
iFFT←{(⍴⍵)÷⍨,(cube+roots⍴⍵)floop cube ⍵}
x
1 2 3 4 5
y
2 3 4 5 6
x xtimes y ⍝ xtimes gives a numeric result, not an error:
2 8 9 5 6 4 3 2 0
12345 × 23456 ⍝ Ordinary multiplication gives the corresponding result:
289564320
FFT¨x extend y ⍝ This subexpression from xtimes generates an error:
RANK ERROR: Invalid axis
floop[0] floop←{(⊣/⍺)∇⍣(×m)⊢(+⌿⍵),[m-0.5]⍺×[⍳m←≢⍴⍺]-⌿⍵}
roots←{×\1,1↓(⍵÷2)⍴¯1*2÷⍵}
cube←{⍵⍴⍨2⍴⍨2⍟⍴⍵}
extend←{(2*⌈2⍟¯1+(⍴⍺)+⍴⍵)↑¨⍺ ⍵}
floop←{(⊣/⍺)∇⍣(×m)⊢(+⌿⍵),[m-0.5]⍺×[⍳m←≢⍴⍺]-⌿⍵}
FFT←{,(cube roots⍴⍵)floop cube ⍵}
iFFT←{(⍴⍵)÷⍨,(cube+roots⍴⍵)floop cube ⍵}
Re: something wrong with dfns FFT
Duh! Never mind. ⎕IO needs to be 0 in the execution environment. Note to self: when in doubt, study the code.