% ECE 111 Lecture #7 % 10-stage RC filter V = zeros(10,1); dV = zeros(10,1); V0 = 10; dt = 0.01; t = 0; y = []; while(t < 9.9) dV(1) = 10*V0 - 20.1*V(1) + 10*V(2); dV(2) = 10*V(1) - 20.1*V(2) + 10*V(3); dV(3) = 10*V(2) - 20.1*V(3) + 10*V(4); dV(4) = 10*V(3) - 20.1*V(4) + 10*V(5); dV(5) = 10*V(4) - 20.1*V(5) + 10*V(6); dV(6) = 10*V(5) - 20.1*V(6) + 10*V(7); dV(7) = 10*V(6) - 20.1*V(7) + 10*V(8); dV(8) = 10*V(7) - 20.1*V(8) + 10*V(9); dV(9) = 10*V(8) - 20.1*V(9) + 10*V(10); dV(10) = 10*V(9) - 10.1*V(10); V = V + dV*dt; t = t + dt; plot([0:10], [V0;V], '.-', t, 0, 'r+'); ylim([0,10]); pause(0.01); y = [y ; [V0;V]']; end pause(5); t = [1:length(y)]' * dt; plot(t,y);