Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,7 @@
|
|||
with Ada.Numerics.Generic_Complex_Arrays;
|
||||
|
||||
generic
|
||||
with package Complex_Arrays is
|
||||
new Ada.Numerics.Generic_Complex_Arrays (<>);
|
||||
use Complex_Arrays;
|
||||
function Generic_FFT (X : Complex_Vector) return Complex_Vector;
|
||||
39
Task/Fast-Fourier-transform/Ada/fast-fourier-transform-2.adb
Normal file
39
Task/Fast-Fourier-transform/Ada/fast-fourier-transform-2.adb
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
with Ada.Numerics;
|
||||
with Ada.Numerics.Generic_Complex_Elementary_Functions;
|
||||
|
||||
function Generic_FFT (X : Complex_Vector) return Complex_Vector is
|
||||
|
||||
package Complex_Elementary_Functions is
|
||||
new Ada.Numerics.Generic_Complex_Elementary_Functions
|
||||
(Complex_Arrays.Complex_Types);
|
||||
|
||||
use Ada.Numerics;
|
||||
use Complex_Elementary_Functions;
|
||||
use Complex_Arrays.Complex_Types;
|
||||
|
||||
function FFT (X : Complex_Vector; N, S : Positive)
|
||||
return Complex_Vector is
|
||||
begin
|
||||
if N = 1 then
|
||||
return (1..1 => X (X'First));
|
||||
else
|
||||
declare
|
||||
F : constant Complex := exp (Pi * j / Real_Arrays.Real (N/2));
|
||||
Even : Complex_Vector := FFT (X, N/2, 2*S);
|
||||
Odd : Complex_Vector := FFT (X (X'First + S..X'Last), N/2, 2*S);
|
||||
begin
|
||||
for K in 0..N/2 - 1 loop
|
||||
declare
|
||||
T : constant Complex := Odd (Odd'First + K) / F ** K;
|
||||
begin
|
||||
Odd (Odd'First + K) := Even (Even'First + K) - T;
|
||||
Even (Even'First + K) := Even (Even'First + K) + T;
|
||||
end;
|
||||
end loop;
|
||||
return Even & Odd;
|
||||
end;
|
||||
end if;
|
||||
end FFT;
|
||||
begin
|
||||
return FFT (X, X'Length, 1);
|
||||
end Generic_FFT;
|
||||
20
Task/Fast-Fourier-transform/Ada/fast-fourier-transform-3.adb
Normal file
20
Task/Fast-Fourier-transform/Ada/fast-fourier-transform-3.adb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
with Ada.Numerics.Complex_Arrays; use Ada.Numerics.Complex_Arrays;
|
||||
with Ada.Complex_Text_IO; use Ada.Complex_Text_IO;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
with Ada.Numerics.Complex_Elementary_Functions;
|
||||
with Generic_FFT;
|
||||
|
||||
procedure Example is
|
||||
function FFT is new Generic_FFT (Ada.Numerics.Complex_Arrays);
|
||||
X : Complex_Vector := (1..4 => (1.0, 0.0), 5..8 => (0.0, 0.0));
|
||||
Y : Complex_Vector := FFT (X);
|
||||
begin
|
||||
Put_Line (" X FFT X ");
|
||||
for I in Y'Range loop
|
||||
Put (X (I - Y'First + X'First), Aft => 3, Exp => 0);
|
||||
Put (" ");
|
||||
Put (Y (I), Aft => 3, Exp => 0);
|
||||
New_Line;
|
||||
end loop;
|
||||
end;
|
||||
|
|
@ -17,3 +17,49 @@ module FFT {
|
|||
End Sub
|
||||
}
|
||||
FFT
|
||||
' FFT run on newer M2000 Interpreter's versions also.
|
||||
' Version using Complex type (from Version 13 of M2000 Interpreter)
|
||||
' locale 1033 display dot for decimal point.
|
||||
module FFT2 {
|
||||
' print $("0.000", 16) ' #1 (use #1, #2, #3 for 4 decimals for printing numbers )
|
||||
locale 1033
|
||||
open "output.txt" for wide output as #F
|
||||
complex buf[7], out[7]
|
||||
buf[0]|r = 1: buf[1]|r = 1: buf[2]|r = 1: buf[3] = (1, 0i)
|
||||
showArr(buf, "Input")
|
||||
FFT(out, buf, 0, 1, 8)
|
||||
ShowArr(out, "Output")
|
||||
' print $("") ' #2
|
||||
close #F
|
||||
print #-2, eval$(buffer(dir$+"output.txt"))
|
||||
Sub ShowArr(m, mes as string)
|
||||
local n, mx=len(m)
|
||||
print #F, mes;": (real imag abs)"
|
||||
while n<mx
|
||||
' print m[n] ' #3
|
||||
' round(number) round to 13th decimal, is same as round(exp, 13)
|
||||
' modulus Mod(complex)
|
||||
print #F, format$("{0:0:-10} {1:-10} {2:-12}",m[n]|r, round(m[n]|i, 4)+"", round(mod(m[n]), 8)+"")
|
||||
n++
|
||||
end while
|
||||
End Sub
|
||||
Sub FFT()
|
||||
Shift 5
|
||||
Read New N as long
|
||||
FFT1()
|
||||
End Sub
|
||||
' FFT1() use N always
|
||||
Sub FFT1(buf as *Complex[], out as *Complex[], begin as Long, stp as Long)
|
||||
If stp < N Then
|
||||
FFT1(out, buf, begin, 2 * stp)
|
||||
FFT1(out, buf, begin + stp, 2 * stp)
|
||||
Local i as long, t as complex
|
||||
for i=0 to N-1 step 2*stp
|
||||
t = Polar(1, -pi* i / N) * out[begin + i + stp]
|
||||
buf[begin + i div 2] = out[begin + i] + t
|
||||
buf[begin + (i + N) div 2] = out[begin + i] - t
|
||||
next
|
||||
End If
|
||||
End Sub
|
||||
}
|
||||
FFT2
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
require "complex"
|
||||
|
||||
local function ditfft2(x, y, n, s)
|
||||
if n == 1 then
|
||||
y[1] = complex.of(x[1])
|
||||
return
|
||||
end
|
||||
local hn = n // 2
|
||||
ditfft2(x, y, hn, 2 * s)
|
||||
local z = y:slice(hn + 1)
|
||||
ditfft2(x:slice(s + 1), z, hn, 2 * s)
|
||||
for i = hn + 1, #y do y[i] = z[i - hn] end
|
||||
for k = 1, hn do
|
||||
local tf = complex.polar(1, -2 * math.pi * (k - 1) / n) * y[k + hn]
|
||||
local t = y[k]
|
||||
y[k] += tf
|
||||
y[k + hn] = t - tf
|
||||
end
|
||||
end
|
||||
|
||||
local x = {1, 1, 1, 1, 0, 0, 0, 0}
|
||||
local y = table.create(#x)
|
||||
for i = 1, #x do y[i] = complex.of(0) end
|
||||
ditfft2(x, y, #x, 1)
|
||||
for y as c do print(c:format("%6.4f")) end
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
Function FFT($Arr){
|
||||
$Len = $Arr.Count
|
||||
|
||||
If($Len -le 1){Return $Arr}
|
||||
|
||||
$Len_Over_2 = [Math]::Floor(($Len/2))
|
||||
|
||||
$Output = New-Object System.Numerics.Complex[] $Len
|
||||
|
||||
$EvenArr = @()
|
||||
$OddArr = @()
|
||||
|
||||
For($i = 0; $i -lt $Len; $i++){
|
||||
If($i % 2){
|
||||
$OddArr+=$Arr[$i]
|
||||
}Else{
|
||||
$EvenArr+=$Arr[$i]
|
||||
}
|
||||
}
|
||||
|
||||
$Even = FFT($EvenArr)
|
||||
$Odd = FFT($OddArr)
|
||||
|
||||
For($i = 0; $i -lt $Len_Over_2; $i++){
|
||||
$Twiddle = [System.Numerics.Complex]::Exp([System.Numerics.Complex]::ImaginaryOne*[Math]::Pi*($i*-2/$Len))*$Odd[$i]
|
||||
|
||||
$Output[$i] = $Even[$i] + $Twiddle
|
||||
$Output[$i+$Len_Over_2] = $Even[$i] - $Twiddle
|
||||
}
|
||||
|
||||
Return $Output
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import math.complex
|
||||
import math
|
||||
import math.complex { Complex, complex }
|
||||
import math { cos, sin }
|
||||
|
||||
fn ditfft2(x []f64, mut y []Complex, n int, s int) {
|
||||
if n == 1 {
|
||||
y[0] = complex(x[0], 0)
|
||||
|
|
@ -8,7 +9,8 @@ fn ditfft2(x []f64, mut y []Complex, n int, s int) {
|
|||
ditfft2(x, mut y, n/2, 2*s)
|
||||
ditfft2(x[s..], mut y[n/2..], n/2, 2*s)
|
||||
for k := 0; k < n/2; k++ {
|
||||
tf := cmplx.Rect(1, -2*math.pi*f64(k)/f64(n)) * y[k+n/2]
|
||||
theta := -2*math.pi*f64(k)/f64(n)
|
||||
tf := complex(cos(theta), sin(theta)) * y[k+n/2]
|
||||
y[k], y[k+n/2] = y[k]+tf, y[k]-tf
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +20,12 @@ fn main() {
|
|||
mut y := []Complex{len: x.len}
|
||||
ditfft2(x, mut y, x.len, 1)
|
||||
for c in y {
|
||||
println("${c:8.4f}")
|
||||
mut ci := c.im
|
||||
mut sign := '+'
|
||||
if ci < 0.0 {
|
||||
sign = '-'
|
||||
ci = -ci
|
||||
}
|
||||
println("${c.re:6.4f} ${sign} ${ci:6.4f}i")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue