* SPICE netlist
V1 ac1 ac2 SINE(0 318 50)
XU1 opto_a opto_k zero 0 PC817 Igain=1m ;pnba A)K)C)E
R1 N002 ac1 47k
D1 opto_k opto_a 1N4007
R2 N005 ac2 47k
R3 zero vcc 10k
V2 vcc 0 5
C1 0 ac2 1n V=2k
D2 N002 opto_a 1N4007
D3 N005 opto_a 1N4007
D4 opto_k N002 1N4007
D5 opto_k N005 1N4007
XU2 div N001 vcc 0 N003 ADA4665 ;pnba In+)In-)V+)V-)OUT
R4 zero N001 100k
R5 div vcc 10k
R6 0 div 22k
Q1 out N004 0 0 2N3904
R7 N003 N004 1k
R8 N004 0 47k
R9 out vcc 10k
R10 N003 0 1k
R11 N003 div 16k
C2 N001 0 2.2n
.tran 50m

* LTspice schematic (.asc)
Version 4
SHEET 1 1424 384
WIRE 88 -192 24 -192
WIRE 264 -192 88 -192
WIRE 392 -192 264 -192
WIRE 680 -192 392 -192
WIRE 680 -176 680 -192
WIRE 24 -144 24 -192
WIRE 264 -144 264 -192
WIRE -344 -80 -408 -80
WIRE -296 -80 -344 -80
WIRE 680 -80 680 -96
WIRE 712 -80 680 -80
WIRE -408 -64 -408 -80
WIRE -344 -64 -344 -80
WIRE 680 -64 680 -80
WIRE 392 -48 392 -192
WIRE -296 -32 -296 -80
WIRE -248 -32 -296 -32
WIRE -232 -32 -248 -32
WIRE -200 -32 -232 -32
WIRE 24 -32 24 -64
WIRE 24 -32 -8 -32
WIRE 72 -32 24 -32
WIRE 104 -32 72 -32
WIRE 200 -32 184 -32
WIRE 360 -32 200 -32
WIRE -664 -16 -712 -16
WIRE -616 -16 -664 -16
WIRE -488 -16 -536 -16
WIRE -232 -16 -232 -32
WIRE 440 -16 424 -16
WIRE 472 -16 440 -16
WIRE 488 -16 472 -16
WIRE 584 -16 568 -16
WIRE 616 -16 584 -16
WIRE 264 0 264 -64
WIRE 296 0 264 0
WIRE 328 0 296 0
WIRE 360 0 328 0
WIRE -488 16 -488 -16
WIRE -408 16 -408 0
WIRE -408 16 -488 16
WIRE 472 16 472 -16
WIRE 584 16 584 -16
WIRE -344 32 -344 0
WIRE -344 32 -488 32
WIRE 200 32 200 -32
WIRE 264 32 264 0
WIRE -408 48 -408 16
WIRE -344 48 -344 32
WIRE 392 48 392 16
WIRE -664 64 -712 64
WIRE -648 64 -664 64
WIRE -616 64 -648 64
WIRE -488 64 -488 32
WIRE -488 64 -536 64
WIRE -248 64 -296 64
WIRE -232 64 -232 48
WIRE -232 64 -248 64
WIRE -200 64 -232 64
WIRE 24 64 -8 64
WIRE 88 80 88 48
WIRE 472 112 472 96
WIRE 584 112 584 96
WIRE 680 112 680 32
WIRE -408 128 -408 112
WIRE -344 128 -344 112
WIRE -344 128 -408 128
WIRE -296 128 -296 64
WIRE -296 128 -344 128
WIRE 200 128 200 96
WIRE 264 128 264 112
WIRE 328 128 328 0
WIRE 344 128 328 128
WIRE 440 128 440 -16
WIRE 440 128 424 128
WIRE -648 160 -648 64
WIRE -152 160 -648 160
WIRE 24 160 24 64
WIRE 24 160 -88 160
WIRE 24 192 24 160
WIRE 88 192 88 160
FLAG 88 48 vcc
FLAG 88 192 0
FLAG 24 192 0
FLAG 88 -192 vcc
FLAG 72 -32 zero
FLAG -664 -16 ac1
FLAG -664 64 ac2
FLAG -248 -32 opto_a
FLAG -248 64 opto_k
FLAG 264 128 0
FLAG 392 48 0
FLAG 712 -80 out
FLAG 296 0 div
FLAG 584 112 0
FLAG 680 112 0
FLAG 472 112 0
FLAG 200 128 0
SYMBOL voltage -712 -32 R0
SYMATTR InstName V1
SYMATTR Value SINE(0 318 50)
SYMBOL Optos\\PC817A -104 16 R0
SYMATTR InstName U1
SYMBOL res -520 -32 R90
SYMATTR InstName R1
SYMATTR Value 47k
SYMBOL diode -216 48 R180
SYMATTR InstName D1
SYMATTR Value 1N4007
SYMBOL res -520 48 R90
SYMATTR InstName R2
SYMATTR Value 47k
SYMBOL res 40 -48 R180
SYMATTR InstName R3
SYMATTR Value 10k
SYMBOL voltage 88 64 R0
SYMATTR InstName V2
SYMATTR Value 5
SYMBOL cap -88 144 R90
SYMATTR InstName C1
SYMATTR Value 1n
SYMATTR SpiceLine V=2k
SYMBOL diode -392 0 R180
SYMATTR InstName D2
SYMATTR Value 1N4007
SYMBOL diode -328 0 R180
SYMATTR InstName D3
SYMATTR Value 1N4007
SYMBOL diode -392 112 R180
SYMATTR InstName D4
SYMATTR Value 1N4007
SYMBOL diode -328 112 R180
SYMATTR InstName D5
SYMATTR Value 1N4007
SYMBOL OpAmps\\ADA4665 392 -80 R0
SYMATTR InstName U2
SYMBOL res 88 -16 R270
SYMATTR InstName R4
SYMATTR Value 100k
SYMBOL res 280 -48 R180
SYMATTR InstName R5
SYMATTR Value 10k
SYMBOL res 280 128 R180
SYMATTR InstName R6
SYMATTR Value 22k
SYMBOL npn 616 -64 R0
SYMATTR InstName Q1
SYMATTR Value 2N3904
SYMBOL res 472 0 R270
SYMATTR InstName R7
SYMATTR Value 1k
SYMBOL res 568 0 R0
SYMATTR InstName R8
SYMATTR Value 47k
SYMBOL res 696 -80 R180
SYMATTR InstName R9
SYMATTR Value 10k
SYMBOL res 456 0 R0
SYMATTR InstName R10
SYMATTR Value 1k
SYMBOL res 440 112 R90
SYMATTR InstName R11
SYMATTR Value 16k
SYMBOL cap 184 32 R0
SYMATTR InstName C2
SYMATTR Value 2.2n