procedure TSpectrum.FFT(Dat:
array of TComplex);
var
i, j, n, K , io, ie, in_, nn: Integer;
u,
tp, tq, w: TComplex;
sr, mGain: Single;
function LimitedSingleValue(doubleVal: double): single;
begin
if doubleVal > MaxSingle
then
result := MaxSingle
else if doubleVal < MinSingle
then
result := MinSingle
else
result := doubleVal;
end;
begin
if not FFTInit
then
begin
InitFFT;
FFTInit := True;
end;
nn := FFFTSize
div 2;
ie := FFFTSize;
for n := 1
to FFTLog
do
begin
w := Coef[FFTLog - n];
in_ := ie
div 2;
u.r := 1;
u.i := 0;
for j := 0
to (in_ - 1)
do
begin
for i := j
to (FFFTSize - 1)
do
begin
if i
mod ie <> 0
then
continue;
io := i + in_;
if (i >= (FFFTSize - 1))
or (io >= (FFFTSize - 1))
then
continue;
tp.r := LimitedSingleValue(Dat[i].r + Dat[io].r);
tp.i := LimitedSingleValue(Dat[i].i + Dat[io].i);
tq.r := Dat[i].r - Dat[io].r;
tq.i := Dat[i].i - Dat[io].i;
Dat[io].r := tq.r * u.r - tq.i * u.i;
Dat[io].i := LimitedSingleValue(tq.i * u.r + tq.r * u.i);
Dat[i] :=
tp;
end;
sr := u.r;
u.r := u.r * w.r - u.i * w.i;
u.i := u.i * w.r + sr * w.i;
end;
ie := ie
div 2;
end;
j := 1;
for i := 1
to (FFFTSize - 1)
do
begin
if i < j
then
begin
io := i - 1;
in_ := j - 1;
tp := Dat[in_];
Dat[in_] := Dat[io];
Dat[io] :=
tp;
end;
K := nn;
While K < j
do
begin
j := j - K;
K := K
div 2;
end;
j := j + K;
end;
mGain := (FGain / 100);
if FView = 0
then
sr := (4096 * mGain) / FFFTSize
else
sr := 1 / FFFTSize;
for i := 0
to (FFFTSize
div 2) - 1
do
begin
Dat[i].r := Dat[i].r * sr;
Dat[i].i := Dat[i].i * sr;
end;
end;