unit Peak_Emulator; interface const cMassScale=1000; {измерение масс в 1/1000 аем} cSignalScale=1000; {измерение сигнала в 1/1000} cNoiseScale=10000; cMaxPeakCount=1000; cDefaultPeakCount=200; function xRandom(Min,Max:integer):extended; type tMass=cardinal; tSignal=cardinal; tPeakCount=0..cMaxPeakCount; tPeak=object private Center:tMass; Sigma:tMass; Amplitude:tSignal; Noise:tSignal; LowNeigbour,UpNeigbour:tPeakCount; public procedure Init; function Valid:boolean; function AddNoise:boolean; procedure SetSigma(s:tMass); procedure SetCenter(m:tMass); procedure SetAmplitude(a:tSignal); procedure SetNoise(n:tSignal); procedure SetLowNeibour(n:tPeakCount); procedure SetUpNeibour(n:tPeakCount); function GetCenter:tMass; function GetSigma:tMass; function GetAmplitude:tSignal; function GetNoise:tSignal; function GetUpNeigbour:tPeakCount; function GetLowNeigbour:tPeakCount; function Signal(m:tMass):tSignal; end; implementation function xRandom(Min,Max:integer):extended; begin {$IfOpt R+} if Max<=Min then RunError(201); {$EndIf} xRandom:=Min+random(Max-Min); end; procedure tPeak.Init; begin Center:=0; Sigma:=0; Amplitude:=0; Noise:=1; randomize; end; function tPeak.Valid:boolean; begin Valid:=(Center>0) and (Sigma>0) and (Amplitude>0); end; function tPeak.AddNoise:boolean; begin AddNoise:=(Noise>0); end; procedure tPeak.SetCenter(M:tMass); begin Center:=M; end; procedure tPeak.SetSigma(S:tMass); begin Sigma:=S; end; procedure tPeak.SetAmplitude(a:tSignal); begin Amplitude:=A; end; procedure tPeak.SetNoise(n:tSignal); begin Noise:=n; end; procedure tPeak.SetLowNeibour(n:tPeakCount); begin LowNeigbour:=n; end; procedure tPeak.SetUpNeibour(n:tPeakCount); begin UpNeigbour:=n; end; function tPeak.GetCenter:tMass; begin GetCenter:=Center; end; function tPeak.GetSigma:tMass; begin GetSigma:=Sigma; end; function tPeak.GetAmplitude:tSignal; begin GetAmplitude:=Amplitude; end; function tPeak.GetNoise:tSignal; begin GetNoise:=Noise; end; function tPeak.GetUpNeigbour:tPeakCount; begin GetUpNeigbour:=UpNeigbour; end; function tPeak.GetLowNeigbour:tPeakCount; begin GetLowNeigbour:=LowNeigbour; end; function tPeak.Signal(m:tMass):tSignal; var x:Double; const cSqrt2PI=2.5066282746310005024; begin if Valid then begin x:=Amplitude*(exp(0.5*Sqr((m-Center)/Sigma))/(cSqrt2PI*Sigma)); if AddNoise then begin x:=x+(Noise/cNoiseScale)*random; end; Signal:=Round(x); end else begin Signal:=0; end; end; end.