Procedure FOUR1(var DATA:array of real; NN, ISIGN:integer);
var
N,J,JJ,I,M,II,MM,ISTEP,MMAX:integer;
THETA,WR,WI,WPR,SUM,WTEMP,Y1,Y2,TEMPR,TEMPI,WPI:real;
begin
N:=2 * NN;
J:=1;
For II:=1 To NN do
begin
I:= II * 2 - 1;
If J > I Then
begin
TEMPR:=DATA[J];
TEMPI:=DATA[J + 1];
DATA[J]:=DATA[I];
DATA[J + 1]:=DATA[I + 1];
DATA[I]:=TEMPR;
DATA[I + 1]:=TEMPI;
end;
M:=N div 2;
While (M >= 2) And (J > M) do
begin
J:=J - M;
M:=M div 2;
end;
J:=J + M;
end;
MMAX:=2;
While N > MMAX do
begin
ISTEP:=2 * MMAX;
THETA:=6.28318530717959 / (ISIGN * MMAX);
WPR:=-2 * Sqr(Sin(0.5 * THETA));
WPI:=Sin(THETA);
WR:=1;
WI:=0;
For II:=1 To (MMAX div 2) do
begin
M:= II * 2 - 1;
For JJ:=0 To ((N-M) div ISTEP) do
begin
I:= M + JJ*ISTEP ;
J:=I + MMAX;
TEMPR:=WR * DATA[J] - WI * DATA[J + 1];
TEMPI:=WR * DATA[J + 1] + WI * DATA[J];
DATA[J]:=DATA[I] - TEMPR;
DATA[J + 1]:=DATA[I + 1] - TEMPI;
DATA[I]:=DATA[I] + TEMPR;
DATA[I + 1]:=DATA[I + 1] + TEMPI;
end;
WTEMP:=WR;
WR:=WR * WPR - WI * WPI + WR;
WI:=WI * WPR + WTEMP * WPI + WI;
end;
MMAX:=ISTEP;
end;
end;