fork download
  1. // To understand:
  2. // high(x) is length of array x - 1
  3. // Fmax(x) is 2 element vector addition
  4. // Fmul(x) is 2 element vector addition
  5. // inc(i, l2) is i += l2;
  6. procedure ComplexFFT(dir: integer; var x: array of complex);
  7. var i,i1,i2,j,k,l,l1,l2,n: integer;
  8. t1,u,c: complex;
  9. m: integer;
  10. begin
  11.  
  12. for m := 0 to 16 do
  13. if (1 shl m) >= high(x) then break;
  14. // calculate the number of points
  15. n := 1;
  16. for i := 0 to m-1 do
  17. n := n shl 1;
  18. // do the bit reversal
  19.  
  20. i2 := n shr 1;
  21. j := 0;
  22.  
  23. for i := 0 to n-2 do
  24. begin
  25. if i < j then ComplexSwap(x[i],x[j]);
  26. k := i2;
  27. while k <= j do
  28. begin
  29. j := j - k;
  30. k := k shr 1;
  31. end;
  32. inc(j,k);
  33. end;
  34.  
  35. // compute the FFT
  36. c := Makefloat(-1,0);
  37. l2 := 1;
  38. for l := 0 to m-1 do
  39. begin
  40. l1 := l2;
  41. l2 := l2 shl 1;
  42. u := Makefloat(1,0);
  43. for j := 0 to l1-1 do
  44. begin
  45. i := j;
  46. while i < n do
  47. begin
  48. i1 := i + l1;
  49. t1 := Complexmul(u,x[i1]);
  50. x[i1] := Fsub(x[i],t1);
  51. x[i] := Fadd(x[i],t1);
  52. inc(i,l2);
  53. end;
  54. u := Complexmul(u,c);
  55. end;
  56. c[1] := sqrt((1.0-c[0])*0.5);
  57. if dir = 1 then c[1] := -c[1];
  58. c[0] := sqrt((1.0+c[0])*0.5);
  59. end;
  60. // scaling for forward transformation
  61. if dir = 1 then
  62. begin
  63. for i := 0 to n-1 do
  64. begin
  65. x[i] := Fmul(x[i],1/n);
  66. end;
  67. end;
  68. end;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Free Pascal Compiler version 2.2.0 [2009/11/16] for i386
Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for i386
Compiling prog.pas
prog.pas(6,59) Error: Identifier not found "complex"
prog.pas(8,20) Error: Identifier not found "complex"
prog.pas(8,20) Error: Error in type definition
prog.pas(25,30) Error: Identifier not found "ComplexSwap"
prog.pas(25,41) Error: Illegal expression
prog.pas(36,17) Error: Identifier not found "Makefloat"
prog.pas(42,19) Error: Identifier not found "Makefloat"
prog.pas(49,25) Error: Identifier not found "Complexmul"
prog.pas(50,22) Error: Identifier not found "Fsub"
prog.pas(51,21) Error: Identifier not found "Fadd"
prog.pas(54,22) Error: Identifier not found "Complexmul"
prog.pas(56,7) Error: Illegal qualifier
prog.pas(56,25) Error: Illegal qualifier
prog.pas(57,23) Error: Illegal qualifier
prog.pas(57,32) Error: Illegal qualifier
prog.pas(58,7) Error: Illegal qualifier
prog.pas(58,25) Error: Illegal qualifier
prog.pas(65,19) Error: Identifier not found "Fmul"
prog.pas(68,4) Fatal: Syntax error, "BEGIN" expected but "end of file" found
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
stdout
Standard output is empty