unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TMessDaten =
class (TObject)
Daten:
array of Byte;
Mittelwerte:
array of double;
procedure Add(
const Value: Byte);
procedure Clear;
procedure CreateMittelwerte;
function DivN (
const I: integer): boolean;
function Mittelwert (
const W: double): double;
private
N: integer;
public
constructor Create;
destructor Destroy;
override;
end;
TForm1 =
class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure MachWasMitMittelwerten;
procedure Timer1Timer(Sender: TObject);
private
MessDaten: TMessDaten;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TMessDaten.Clear;
begin
SetLength(Daten, 0);
SetLength(Mittelwerte, 0);
end;
constructor TMessDaten.Create;
begin
inherited Create;
Clear;
N:= 100;
end;
destructor TMessDaten.Destroy;
begin
Clear;
inherited Destroy;
end;
procedure TMessDaten.Add(
const Value: Byte);
var
Count: integer;
begin
Count:= Length(Daten);
Inc(Count);
SetLength(Daten, Count);
Daten[Count-1]:= Value;
end;
function TMessDaten.DivN (
const I: integer): boolean;
begin
Result:= ((I
mod N) = 0);
end;
function TMessDaten.Mittelwert (
const W: double): double;
begin
Result:= W/N;
if Result > 0.7
then Result:= 1;
if Result < 0.3
then Result:= 0;
end;
procedure TMessDaten.CreateMittelwerte;
var
I, J: integer;
W: double;
begin
I:= -1;
J:= -1;
W:= 0;
SetLength(Mittelwerte, 0);
while I < Length(Daten)-1
do
begin
Inc(I);
W:= W+Daten[I];
if DivN(I+1)
then
begin
Inc(J);
SetLength(Mittelwerte, J+1);
Mittelwerte[J]:= Mittelwert(W);
W:= 0;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MessDaten:= TMessDaten.Create;
Randomize;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MessDaten.Free;
end;
procedure TForm1.MachWasMitMittelwerten;
var
I, Count: integer;
W: double;
begin
Messdaten.CreateMittelwerte;
Count:= Length(MessDaten.Mittelwerte);
W:= 0;
for I:= 0
to Count-1
do
W:= W+MessDaten.Mittelwerte[I]/Count;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Messdaten.Add(Random(Succ(1)));
end;
end.