//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "include.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
double dE=1;
double w1=600,w2=3000;


dcomplex __fastcall  F2_1(double t);
dcomplex __fastcall  F3_1(double t);

dcomplex __fastcall S(double x);

//Функция S(iw)
double __fastcall  F1(double w)
{
if (ActiveGraph->Mode==ABS) return (abs (S(w)));
if (ActiveGraph->Mode== RE) return (real(S(w)));
if (ActiveGraph->Mode== IM) return (imag(S(w)));
return 0;
}

//Обратное преобразование Фурье
double __fastcall  F2(double t)
{
if (ActiveGraph->Mode==ABS) return (abs (F2_1(t)));
if (ActiveGraph->Mode== RE) return (real(F2_1(t)));
if (ActiveGraph->Mode== IM) return (imag(F2_1(t)));
return 0;
}

//Прямое преобразование Фурье
double __fastcall  F3(double t)
{
if (ActiveGraph->Mode==ABS) return (abs (F3_1(t)));
if (ActiveGraph->Mode== RE) return (real(F3_1(t)));
if (ActiveGraph->Mode== IM) return (imag(F3_1(t)));
return 0;
}

dcomplex __fastcall  F2_1(double t)
{
double w;
dcomplex y,sum(0,0);
dcomplex e1,e2,e3;

e1=dcomplex(cos(t*w1),sin(t*w1));        //exp(iwt);
e3=dcomplex(cos(t*dE),sin(t*dE));        //exp(itdE)
e2=e1;

for (w=w1;w<=w2;w+=dE)
{
        y=S(w)*e2;              //y=S(w)*exp(itw1);
        sum+=y*dE;              //Площадь
        e2*=e3;                 //e2=exp(it(w+dE))
}
sum/=2*M_PI;
return (sum);
}


dcomplex __fastcall  F3_1(double t)
{
double w;
dcomplex y,sum(0,0);
dcomplex e1,e2,e3;

e1=dcomplex(cos(-t*w1),sin(-t*w1));        //exp(-iwt);
e3=dcomplex(cos(-t*dE),sin(-t*dE));        //exp(-itdE)
e2=e1;

for (w=w1;w<=w2;w+=dE)
{
        y=S(w)*e2;              //y=S(w)*exp(itw1);
        sum+=y*dE;              //Площадь
        e2*=e3;                 //e2=exp(it(w+dE))
}
return (sum);
}


dcomplex __fastcall  S(double x)
{
Var[VarX].Value=dcomplex(x,0);
return Math.F();
}

