Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
23
Добавлен:
30.04.2019
Размер:
9.16 Кб
Скачать
unit OSUnit2;

interface

uses
Classes, ExtCtrls, Graphics, Sysutils;

type
PReal = ^Real;

TNet = class(TObject)
public
X: TList;
Y: TList;
U: TList;
E: TList;
ACP: TList;
MaxX: Real;
MaxY: Real;
MaxU: Real;
MaxE: Real;
MaxAcp: Real;
PointsNumber: longint;
TimeStep: real;
T: real; //Период отсчетов.
T1: real; //Постоянная времени.
constructor Create; overload;
constructor Create(PointsNum: integer); overload;
destructor Destroy; override;
procedure CreatePoints(SignalType: byte); //0-Дельта функция, 1 - случайный и тд.
procedure Calculate;
private
procedure DestroyList(List: TList);
procedure CreateLists;
procedure DestroyLists;
function HObj(Time: real): real;
function HOs(Time: real): real;
end;

function Delta(t: real): real;
procedure InitImage(Image: TImage);
procedure DrawSignal(List: TList; Image: TImage; XShift, YShift: integer; XScale, YScale: real);
procedure SpecialDraw(List: TList; Image: TImage; XShift, YShift: integer; XScale, YScale: real; S: string);

implementation

constructor TNet.Create;
begin
inherited Create;
with Self do
begin
PointsNumber := 200;
TimeStep := 0.1;
T := 5;
T1 := 5;
CreateLists;
X := TList.Create;
end;
end;

constructor TNet.Create(PointsNum: integer);
begin
inherited Create;
with Self do
begin
PointsNumber := PointsNum;
TimeStep := 0.1;
T := 5;
T1 := 5;
CreateLists;
X := TList.Create;
end;
end;

destructor TNet.Destroy;
begin
inherited Destroy;
with Self do
begin
DestroyLists;
DestroyList(X);
end;
end;

procedure TNet.DestroyList(List:TList);
var
i: longint;
p: pointer;
begin
for i := 0 to (List.Count - 1) do
begin
p := List.Items[i];
Dispose(p);
end;
List.Free;
end;

procedure TNet.CreatePoints(SignalType: byte);
var
i: longint;
temp: PReal;
tempmax: Real;
begin
tempMax := -1;
DestroyList(X);
X := TList.Create;
case SignalType of
0: //Дельта функция Дирака.
begin
for i :=0 to PointsNumber - 1 do
begin
new(temp);
temp^ := Delta(i*TimeStep);
X.Add(temp);
if temp^ > tempmax then
tempmax := temp^;
end;
MaxX := tempmax;
end;
1: //Случайный сигнал.
begin
randomize;
for i :=0 to PointsNumber - 1 do
begin
new(temp);
temp^ := random;
X.Add(temp);
if temp^ > tempmax then
tempmax := temp^;
end;
MaxX := tempmax;
end;
2: //Постоянный = 1
begin
randomize;
for i :=0 to PointsNumber - 1 do
begin
new(temp);
temp^ := 1;
X.Add(temp);
if temp^ > tempmax then
tempmax := temp^;
end;
MaxX := tempmax;
end;
end;
end;

procedure TNet.Calculate;
var
i, j, h, k: longint;
temp, temp1, tempMaxY, tempMaxU, tempMaxE, tempMaxACP : real;
tempx, tempy, tempe, tempu, tempu1, tempACP, tempACP1: PReal;
begin
DestroyLists;
CreateLists;
tempMaxU := 0;
tempMaxE := 0;
tempMaxACP := 0;
tempMaxY := 0;

new(tempU);
new(tempACP);
tempU^ := 0;
tempACP^ := 0;
U.Add(tempU);
ACP.Add(tempACP);

for j := 0 to (PointsNumber - 1) do
begin
temp := 0;

new(tempe);
tempU := U.Items[j];
tempX := X.Items[j];
tempE^ := tempX^ - tempU^;
E.Add(tempE);
if tempE^ > tempMaxE then
tempMaxE := tempE^;

for i := 0 to j do
begin
tempe := E.Items[i];
temp := temp + tempe^ * HObj(j - i);
end;
new(tempy);
tempy^ := temp;
Y.Add(tempy);
if temp > tempMaxY then
tempMaxY := temp;

if ((j mod (trunc(T))) = 0) then
begin
new(tempACP);
tempACP^ := temp;
ACP.Add(tempACP);
if tempACP^ > tempMaxACP then
tempMaxACP := tempACP^;
temp1 := 0;
for k := 1 to j+1 do
begin
tempACP := ACP.Items[k];
temp1 := temp1 + tempACP^*HOs(j+1 - k);
end;
new(tempu);
tempU^ := temp1;
U.Add(tempU);
if temp1 > tempMaxU then
tempMaxU := temp1;
end
else
begin
new(tempACP);
tempACP1 := ACP.Items[j];
tempACP^ := tempACP1^;
ACP.Add(tempACP);
new(tempu);
tempu1 := U.Items[j];
tempu^ := tempu1^;
U.Add(tempu);
end;
end;
MaxY := tempMaxY;
MaxU := tempMaxU;
MaxE := tempMaxE;
maxACP := tempMaxACP;
end;

procedure TNet.CreateLists;
begin
Y := TList.Create;
U := TList.Create;
E := TList.Create;
ACP := TList.Create;
end;

procedure TNet.DestroyLists;
begin
DestroyList(Y);
DestroyList(U);
DestroyList(E);
DestroyList(ACP);
end;

function TNet.HObj(Time: real): real;
begin
if Time < 0 then
Result := 0;
if Time = 0 then
Result := 1 / T1;
if Time > 0 then
Result :=(1 / T1) * exp(-1 * (Time/T1));
end;

function TNet.HOs(Time: real): real;
begin
if Time < 0 then
Result := 0;
if Time = 0 then
Result := 1 / T1;
if Time > 0 then
Result :=(1 / T1) * exp(-1 * (Time/T1));

// Result := 0;
end;





///////////////////////Other functions&procedures/////////////////
function Delta(t: real): real;
begin
if (t=0) then
Result := 1
else
Result := 0;
end;

procedure InitImage(Image:TImage);
begin
Image.Canvas.Brush.Color := clWhite;
Image.Canvas.Pen.Color := clBlack;
Image.Canvas.Rectangle(0, 0, Image.Width, Image.Height);
Image.Canvas.Pen.Color := clBlue;
Image.Canvas.MoveTo(0, trunc(Image.Height/2));
Image.Canvas.LineTo(Image.Width, trunc(Image.Height/2));
Image.Canvas.Pen.Color := clBlack;
end;

procedure DrawSignal(List: TList; Image: TImage; XShift, YShift: integer; XScale, YScale: real);
var
i: longint;
temp: PReal;
begin
// Вывод графиков.
InitImage(Image);
new(temp);
temp^ := 0;
Image.Canvas.MoveTo(XShift, trunc(Image.Height/2) - yshift);
for i := 0 to (List.Count - 1) do
begin
Image.Canvas.LineTo(round(XShift + i*XScale), round(trunc(Image.Height/2) - (YShift + temp^*YScale)));
temp := List.Items[i];
Image.Canvas.LineTo(round(XShift + i*XScale), round(trunc(Image.Height/2) - (YShift + temp^*YScale)));
end;
end;

procedure SpecialDraw(List: TList; Image: TImage; XShift, YShift: integer; XScale, YScale: real; S: string);
var
i: longint;
temp: PReal;
begin
//////////оси
InitImage(Image);
Image.Canvas.Pen.Color := clBlue;
Image.Canvas.MoveTo(Image.Width - 5, trunc(Image.Height/2) - 5);
Image.Canvas.LineTo(Image.Width, trunc(Image.Height/2));
Image.Canvas.LineTo(Image.Width - 5, trunc(Image.Height/2) + 5);
Image.Canvas.MoveTo(xshift, Image.Height);
Image.Canvas.LineTo(xshift, 0);
Image.Canvas.MoveTo(xshift - 5, 5);
Image.Canvas.LineTo(xshift, 0);
Image.Canvas.LineTo(xshift + 5, 5);
Image.Canvas.Font.Color := clRed;
Image.Canvas.Font.Size := 8;

new(temp);
temp^ := 0;
Image.Canvas.MoveTo(XShift, trunc(Image.Height/2) - yshift);
Image.Canvas.Pen.Color := clBlack;
for i := 0 to (List.Count - 1) do
begin
Image.Canvas.LineTo(round(XShift + i*XScale), round(trunc(Image.Height/2) - (YShift + temp^*YScale)));
temp := List.Items[i];
Image.Canvas.LineTo(round(XShift + i*XScale), round(trunc(Image.Height/2) - (YShift + temp^*YScale)));
if ( (i mod (List.Count div 20)) = 0) then
begin
Image.Canvas.Pen.Color := clRed;
Image.Canvas.MoveTo(round(XShift + i*XScale), trunc(Image.Height/2) - 3);
Image.Canvas.LineTo(round(XShift + i*XScale), trunc(Image.Height/2) + 3);
Image.Canvas.TextOut(round(XShift + i*XScale) - 3, trunc(Image.Height/2) + 3, inttostr(i));

Image.Canvas.MoveTo(XShift - 3, round(trunc(Image.Height/2) - (YShift + temp^*YScale)));
Image.Canvas.MoveTo(XShift + 3, round(trunc(Image.Height/2) - (YShift + temp^*YScale)));
Image.Canvas.TextOut(XShift + 5, round(trunc(Image.Height/2) - (YShift + temp^*YScale)), floattostrf(temp^, ffFixed, 2, 2));

Image.Canvas.MoveTo(round(XShift + i*XScale), round(trunc(Image.Height/2) - (YShift + temp^*YScale)));
Image.Canvas.Pen.Color := clBlack;
end;
end;

Image.Canvas.Font.Color := clRed;
Image.Canvas.Font.Size := 12;
Image.Canvas.TextOut(10, Image.Height - 30, S);

end;

end.
Соседние файлы в папке OS4Delphi4
  • #
    30.04.20198.46 Кб23OSUnit1.dfm
  • #
    30.04.201917.09 Кб23OSUnit1.pas
  • #
    30.04.20198.46 Кб23OSUnit1.~df
  • #
    30.04.201917.09 Кб23OSUnit1.~pa
  • #
    30.04.20198.66 Кб24OSUnit2.dcu
  • #
    30.04.20199.16 Кб23OSUnit2.pas
  • #
    30.04.20199.15 Кб23OSUnit2.~pa
  • #
    30.04.20199.44 Кб23OSUnit2v2.dcu
  • #
    30.04.201911.13 Кб23OSUnit2v2.pas
  • #
    30.04.201911.12 Кб23OSUnit2v2.~pa
  • #
    30.04.20192.97 Кб23OSUnit3.dcu