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

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; //Постоянная времени объекта в прямой цепи.
T2: real; //Постоянная времени объекта в обратной цепи.
K1: real; //Коэффициент усиления в прямой цепи.
K2: real; //Коэффициент усиления в обратной цепи.
constructor Create; overload;
constructor Create(PointsNum: integer); overload;
destructor Destroy; override;
procedure CreatePoints(SignalType: byte); //0-Дельта функция, 1 - случайный и тд.
procedure Calculate;
private
WatchTime: integer;
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
WatchTime := 561;
PointsNumber := 200;
TimeStep := WatchTime / PointsNumber;
T := 5;
T1 := 5;
T2 := 5;
K1 := 1;
K2 := 1;
CreateLists;
X := TList.Create;
end;
end;

constructor TNet.Create(PointsNum: integer);
begin
inherited Create;
with Self do
begin
PointsNumber := PointsNum;
T := 5;
T1 := 5;
T2 := 5;
K1 := 1;
K2 := 1;
CreateLists;
X := TList.Create;
WatchTime := 561;
TimeStep := WatchTime / PointsNumber;
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 - 0.5;
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;
tempMaxY, tempMaxU, tempMaxE, tempMaxACP : real;
tempX, tempY, tempE, tempU, tempU1, tempACP, tempACP1, tempY1: PReal;
begin
DestroyLists;
CreateLists;
tempMaxU := 0;
tempMaxE := 0;
tempMaxACP := 0;
tempMaxY := 0;

//Считаем для 0 момента времени.
tempX := X.Items[0];
new(tempE);
tempE^ := tempX^ / (1 + HObj(0)*HOs(0));
E.Add(tempE);
if tempE^ > tempMaxE then
tempMaxE := tempE^;
new(tempY);
tempY^ := tempE^ * HObj(0);
Y.Add(tempY);
if tempY^ > tempMaxY then
tempMaxY := tempY^;
new(tempACP);
tempACP^ := tempY^;
ACP.Add(tempACP);
if tempACP^ > tempMaxACP then
tempMaxACP := tempACP^;
new(tempU);
tempU^ := tempACP^ * HOs(0);
U.Add(tempU);
if tempU^ > tempMaxU then
tempMaxU := tempU^;

//Считаем далее
for j := 1 to (PointsNumber - 1) do
begin
if ((j mod (trunc(T))) = 0) then
begin
//Если такты совпали:
tempX := X.Items[j];
tempU := U.Items[j-1];
tempACP := ACP.Items[j-1];

//Считаем знаечение Е(t)
new(tempE);
tempE^ := (tempX^ - tempU^ - HOs(0) * tempACP^)/ (1 + HObj(0)*HOs(0));
E.Add(tempE);
if tempE^ > tempMaxE then
tempMaxE := tempE^;

//Считаем знаечение Y(t)
tempY1 := Y.Items[j-1];
new(tempY);
tempY^ := tempY1^ + tempE^ * HObj(0);
Y.Add(tempY);
if tempY^ > tempMaxY then
tempMaxY := tempY^;

//Считаем знаечение ACP(t)
new(tempACP);
tempACP^ := tempY^;
ACP.Add(tempACP);
if tempACP^ > tempMaxACP then
tempMaxACP := tempACP^;

//Считаем знаечение U(t)
tempU1 := U.Items[j-1];
new(tempU);
tempU^ := tempU1^ + tempACP^ * HOs(0);
U.Add(tempU);
if tempU^ > tempMaxU then
tempMaxU := tempU^;
end
else
begin
//Если такты не совпали:
tempX := X.Items[j];

//Считаем знаечение Е(t)
tempU := U.Items[j-1];
new(tempE);
tempE^ := tempX^ - tempU^;
E.Add(tempE);
if tempE^ > tempMaxE then
tempMaxE := tempE^;

//Считаем знаечение Y(t)
tempY1 := Y.Items[j-1];
new(tempY);
tempY^ := tempY1^ + tempE^ * HObj(0);
Y.Add(tempY);
if tempY^ > tempMaxY then
tempMaxY := tempY^;

//Считаем знаечение ACP(t)
new(tempACP);
tempACP1 := ACP.Items[j-1];
tempACP^ := tempACP1^;
ACP.Add(tempACP);
if tempACP^ > tempMaxACP then
tempMaxACP := tempACP^;

//Считаем знаечение U(t)
tempU1 := U.Items[j-1];
new(tempU);
tempU^ := tempU1^;
U.Add(tempU);
if tempU^ > tempMaxU then
tempMaxU := 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 := K1 * 1 / T1;
if Time > 0 then
Result := K1 * (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 := K2 * 1 / T2;
if Time > 0 then
Result := K2 * (1 / T2) * exp(-1 * (Time/T2));
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_1
  • #
    30.04.201917.09 Кб23OSUnit1.~pa
  • #
    30.04.20198.66 Кб23OSUnit2.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
  • #
    30.04.2019360 б23OSUnit3.dfm
  • #
    30.04.2019333 б24OSUnit3.pas
  • #
    30.04.2019369 б23OSUnit3.~df