This example uses the optimization feature of CCICAP to help design a cable simulator. CCICAP uses a genetic algorithm to find circuit element values that optimize the circuit response.

Cable simulators are designed to mimic the performance of a specified length of cable. Using a simulator may be more convenient than having several miles of cable in a lab.

This example designs a simple RLC circuit to match the frequency response of 9000 feet of ADSL cable. ADSL cable uses AWG 26 wire so the DC resistance is known. Each section of the simulator consists of a simple RLC low pass filter. The sections are cascaded and the final section is loaded with the characteristic impedance of ADSL cable (100 ohms). Note that the CCICAP analysis uses a single ended model of the cable so that the circuit is loaded with half of the characteristic impedance, 50 ohms.

Each section uses the same values for the RLC elements.

The input file is:

```.title ADSL Cable Simulation, Optimization
' adsl cable is awg 26
' 26 awg dc resistance / foot
.par r26 .041

' simulate 9000 feet of adsl cable
.par L 9000.

' plot amplitude response
.ac 50 10 10.khz 1.Mhz
.plot ac png eout

' optimization controls
.opp 0.05 0.1 0.5 0.1 2000 10 5
' optimize on amplitude
.opm amplitude
' specified frequencies
.opf 150.khz 772.khz
' specified responses
.opr eout 1.0 -23. -51.
' adjust l and c elements
.ope l1 c1
' force sections to be equal
.opc l1 - l2 0. c1 - c2 0.

.ckt
' two section simulation
v ein 1 0 1.
' first rlc section
' dc resistance for each section
r r1 1 2 { L 2 / r26 X }
l l1 2 3 .1m
c c1 3 0 .1u
' second section
r r2 3 4 { r1 }
l l2 4 5 { l1 }
c c2 5 0 { c1 }
' load resistor - 1/2 characteristic impedance
r rl 5 0 50.
' measure output
vm eout 5 0
.end

.go
.stop
```

The .OPP record establishes some optimization parameters including an ending error criteria of .1 dB and a limit of 2000 generations.

The .OPF and .OPR records set the optimization goal of -23 and -51 dB responses at 150 KHz and 772 KHz.

The .OPE record names the two elements that are allowed to change.

The .OPC record forces the values of C and L in each section to be the same.

The parameter records (.PAR) for r26 and L set the values for the wire resistance and the length of the simulated section of cable.

The circuit is defined with appropriate resistance values and a guess for the initial values of C and L for the sections.

The output file from the run contains the following results:

• Initial circuit values
• ``` Circuit Description

Type     Name     Node1    Node2    Node3    Node4    Model/Value(s)
V        ein      1        GND                         1.000E+00  0.000E+00

R        r1       1        2                           1.845E+02
L        l1       2        3                           1.000E-04
C        c1       3        GND                         1.000E-07
R        r2       3        4                           1.845E+02
L        l2       4        5                           1.000E-04
C        c2       5        GND                         1.000E-07
R        rl       5        GND                         5.000E+01
VM       eout     5        GND
```
• Optimization report - initial circuit
• ```Optimization

NOPTE =  2, NOPTF =  2, NOPTR =  2 NCNS  =  2, NLIMS =  0
OPTCHG = 5.0000E-02 OPTSTP = 1.0000E-01 OPTCRO = 5.0000E-01 OPTMUT = 1.0000E-01
Number of Outputs =    1
Optimizing on AMP
Optimzation output, weight
eout       1.000000

Initial Optimization Results for output eout    :
Frequency     Desired Resp. Actual Resp.  Wt'd Error    Actual Error
1.50E+05     -2.30E+01     -5.14E+01      2.84E+01      2.84E+01
7.72E+05     -5.10E+01     -9.59E+01      4.49E+01      4.49E+01

original value  :   l1     1.0000E-04
original value  :   c1     1.0000E-07

Average error =    37.57971
```
• Optimization report - optimized circuit
```Final Optimization Results for output eout    :
Frequency     Desired Resp. Actual Resp.  Wt'd Error    Actual Error
1.50E+05     -2.30E+01     -2.31E+01      1.17E-01      1.17E-01
7.72E+05     -5.10E+01     -5.10E+01     -4.94E-03     -4.94E-03

optimized value   :   l1     4.9312E-05
optimized value   :   c1     1.3269E-08
constrained value :   l2     4.9312E-05
constrained value :   c2     1.3269E-08

Average error =   8.3053559E-02
Number of iterations =          459
```
• Final circuit values
• ``` Circuit Description

V        ein      1        GND                         1.000E+00  0.000E+00

R        r1       1        2                           1.845E+02
L        l1       2        3                           4.931E-05
C        c1       3        GND                         1.327E-08
R        r2       3        4                           1.845E+02
L        l2       4        5                           4.931E-05
C        c2       5        GND                         1.327E-08
R        rl       5        GND                         5.000E+01
VM       eout     5        GND
```

The optimization run also produces plots of the response before and after optimization. The initial and final responses are shown here.