# wien bridge oscillator, state space model
# empty workspace
clear all
close all
# parameters
C1 = 10e-9;
C2 = 10e-9;
R1 = 10e3;
R2 = 10e3;
A = 3;
# initialization
s = zeros(15, 17);
# KCL
s(1, 3) = 1;
s(1, 4) = 1;
s(1, 5) = 1;
s(1, 6) = - 1;
s(2, 6) = 1;
s(2, 7) = - 1;
s(3, 7) = 1;
s(3, 8) = 1;
# KVL
s(4, 13) = - 1;
s(4, 16) = 1;
s(5, 9) = 1;
s(5, 13) = - 1;
s(6, 10) = 1;
s(6, 13) = - 1;
s(7, 11) = 1;
s(7, 13) = 1;
s(7, 14) = - 1;
s(8, 14) = 1;
s(8, 15) = - 1;
s(8, 17) = 1;
s(9, 12) = 1;
s(9, 15) = - 1;
# CE
s(10, 1) = C1;
s(10, 3) = - 1;
s(11, 4) = - R1;
s(11, 9) = 1;
s(12, 5) = 1;
s(13, 6) = - R2;
s(13, 11) = 1;
s(14, 2) = C2;
s(14, 7) = - 1;
s(15, 10) = - A;
s(15, 12) = 1;
# reduce to the standard state space model
sred = rref(s);
A = - sred(1:2, 16:17);
B = - sred(3:15, 16:17);
# check
lambda = eig(A)