-
Notifications
You must be signed in to change notification settings - Fork 1
/
bandpass.pas
124 lines (107 loc) · 3.35 KB
/
bandpass.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
unit BandPass;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LinNetwk, ComplexMath;
type
{ TLowPassFilter }
TLowPassFilter = class(TSerialDipoleCollection)
private
FComplexVoltageTransfer: TComplexQuotient;
function GetComplexVoltageTransfer: TComplexQuotient;
private
R1, C1, RD, R2, R3a, R3b, C3: TStaticLinearDipole;
Z1, Z3a: TParallelDipoleCollection;
Z3aX: TSerialDipoleCollection;
public
constructor Create; {creates the software model}
function VoltageAmplitudeTransfer(AFrequency: Extended): Extended; {
absoulte amplitude based on property ComplexVoltageTransfer }
property ComplexVoltageTransfer: TComplexQuotient
read GetComplexVoltageTransfer; { frequency response function (amplitude-
frequency-function) }
end;
{ TBandPassFilter }
TBandPassFilter = class(TLowPassFilter)
private
C2: TStaticLinearDipole;
RC2: TParallelDipoleCollection;
public
constructor Create;
end;
implementation
{ TLowPassFilter }
function TLowPassFilter.GetComplexVoltageTransfer: TComplexQuotient;
begin
if not Assigned(FComplexVoltageTransfer) then
FComplexVoltageTransfer := TComplexQuotient.Create
else FComplexVoltageTransfer.RemoveOperands;
Z1.Frequency := Frequency;
FComplexVoltageTransfer.AddOperand(Z1.Impedance);
FComplexVoltageTransfer.AddOperand(Impedance);
FComplexVoltageTransfer.Operate;
Result := FComplexVoltageTransfer;
end;
constructor TLowPassFilter.Create;
begin
inherited Create;
{ Modelling the circuit as a software model, field names related to the circuit
diagram }
R3b := TStaticLinearDipole.Create;
R3b.InstanceName := 'R3b';
R3b.Resistance := 11E3{11E3};
AddDipole(R3b);
Z3a := TParallelDipoleCollection.Create;
Z3a.InstanceName := 'Z3a';
R3a := TStaticLinearDipole.Create;
R3a.InstanceName := 'R3a';
R3a.Resistance := 11E3{11E3};
Z3a.AddDipole(R3a);
Z3aX := TSerialDipoleCollection.Create;
Z3aX.InstanceName := 'Z3aX';
C3 := TStaticLinearDipole.Create;
C3.InstanceName := 'C3';
C3.Capacitance := 100E-6;
Z3aX.AddDipole(C3);
R2 := TStaticLinearDipole.Create;
R2.InstanceName := 'R2';
R2.Resistance := 100E3;
Z3aX.AddDipole(R2);
Z1 := TParallelDipoleCollection.Create;
Z1.InstanceName := 'Z1';
R1 := TStaticLinearDipole.Create;
R1.InstanceName := 'R1';
R1.Resistance := 100E3;
Z1.AddDipole(R1);
{RD := TStaticLinearDipole.Create;
RD.InstanceName := 'RD';
RD.Resistance := 12E3;
Z1.AddDipole(RD);}
C1 := TStaticLinearDipole.Create;
C1.InstanceName := 'C1';
C1.Capacitance := 1.4E-8;
Z1.AddDipole(C1);
Z3aX.AddDipole(Z1);
Z3a.AddDipole(Z3aX);
AddDipole(Z3a)
end;
function TLowPassFilter.VoltageAmplitudeTransfer(AFrequency: Extended): Extended;
begin
Frequency := AFrequency;
Result := ComplexVoltageTransfer.Abs;
end;
{ TBandPassFilter }
constructor TBandPassFilter.Create;
begin
inherited Create; {based on TLowPassFilter}
{ adding C2 to the model }
RC2 := TParallelDipoleCollection.Create; {creating a parallel circuit}
RC2.InstanceName := 'RC2';
Z3aX.RemoveDipole(R2); {moving R2 from the previous place ...}
RC2.AddDipole(R2); {... to the new parallel circuit}
C2 := TStaticLinearDipole.Create; {creating, ...}
C2.Capacitance := 1E-6; {... configuring, ...}
RC2.AddDipole(C2); {... and adding C2}
Z3aX.AddDipole(RC2); {adding RC2 to the model in the previous R2 position}
end;
end.