From: <par...@us...> - 2012-09-13 08:09:18
|
Revision: 11001 http://octave.svn.sourceforge.net/octave/?rev=11001&view=rev Author: paramaniac Date: 2012-09-13 08:09:07 +0000 (Thu, 13 Sep 2012) Log Message: ----------- control: work on multiplot feature Modified Paths: -------------- trunk/octave-forge/main/control/devel/__frequency_response_2__.m trunk/octave-forge/main/control/devel/__frequency_vector_2__.m trunk/octave-forge/main/control/devel/bode2.m Added Paths: ----------- trunk/octave-forge/main/control/devel/multiplot2.m Modified: trunk/octave-forge/main/control/devel/__frequency_response_2__.m =================================================================== --- trunk/octave-forge/main/control/devel/__frequency_response_2__.m 2012-09-12 19:03:09 UTC (rev 11000) +++ trunk/octave-forge/main/control/devel/__frequency_response_2__.m 2012-09-13 08:09:07 UTC (rev 11001) @@ -24,24 +24,33 @@ ## Version: 0.4 % function [H, w] = __frequency_response__ (sys, w = [], mimoflag = 0, resptype = 0, wbounds = "std", cellflag = false) -function [H, w] = __frequency_response_2__ (mimoflag = 0, resptype = 0, wbounds = "std", cellflag = false, varargin) +function [H, w] = __frequency_response_2__ (args, mimoflag = 0, resptype = 0, wbounds = "std", cellflag = false) - sys_idx = cellfun (@isa, varargin, {"lti"}); # true or false - w_idx = cellfun (@is_real_vector, varargin); # look for frequency vectors - % ? = cellfun (@iscell, varargin) - % varargin(?) (end) + sys_idx = cellfun (@isa, args, {"lti"}); # true or false + w_idx = cellfun (@is_real_vector, args); # look for frequency vectors + c_idx = cellfun (@iscell, args); + % args(?) (end) % w_idx(end) - if (! any (w_idx)) - w = __frequency_vector_2__ (varargin(sys_idx), wbounds); + if (any (c_idx)) + w = args(c_idx){end}; + if (numel (w) == 2 && issample (w{1}) && issample (w{2})) + w = __frequency_vector_2__ (args(sys_idx), wbounds, w{1}, w{2}); + else + error ("frequency_response: invalid cell"); + endif + elseif (any (w_idx)) + w = args(w_idx){end}; + else + w = __frequency_vector_2__ (args(sys_idx), wbounds); endif -%varargin{sys_idx} +%args{sys_idx} - H = cellfun (@__freqresp__, varargin(sys_idx), {w}, {resptype}, {cellflag}, "uniformoutput", false); + H = cellfun (@__freqresp__, args(sys_idx), {w}, {resptype}, {cellflag}, "uniformoutput", false); %{ ## check arguments Modified: trunk/octave-forge/main/control/devel/__frequency_vector_2__.m =================================================================== --- trunk/octave-forge/main/control/devel/__frequency_vector_2__.m 2012-09-12 19:03:09 UTC (rev 11000) +++ trunk/octave-forge/main/control/devel/__frequency_vector_2__.m 2012-09-13 08:09:07 UTC (rev 11001) @@ -37,7 +37,7 @@ ## Date: October 2009 ## Version: 0.2 -function w = __frequency_vector_2__ (sys_cell, wbounds = "std") +function w = __frequency_vector_2__ (sys_cell, wbounds = "std", wmin, wmax) if (! iscell (sys_cell)) sys_cell = {sys_cell} @@ -48,8 +48,16 @@ [dec_min, dec_max, zp] = cellfun (@(x) __frequency_range__ (x, wbounds), sys_cell, "uniformoutput", false); - dec_min = min (cell2mat (dec_min)); - dec_max = max (cell2mat (dec_max)); + if (nargin == 2) + dec_min = min (cell2mat (dec_min)); + dec_max = max (cell2mat (dec_max)); + elseif (nargin == 4) # w = {wmin, wmax} + dec_min = log10 (wmin); + dec_max = log10 (wmax); + else + print_usage (); + endif + zp = horzcat (zp{:}); ## include zeros and poles for nice peaks in plots Modified: trunk/octave-forge/main/control/devel/bode2.m =================================================================== --- trunk/octave-forge/main/control/devel/bode2.m 2012-09-12 19:03:09 UTC (rev 11000) +++ trunk/octave-forge/main/control/devel/bode2.m 2012-09-13 08:09:07 UTC (rev 11001) @@ -58,7 +58,7 @@ print_usage (); endif - [H, w] = __frequency_response_2__ (false, 0, "std", false, varargin{:}); + [H, w] = __frequency_response_2__ (varargin, false, 0, "std", false); H = cellfun (@reshape, H, {[]}, {1}, "uniformoutput", false); mag = cellfun (@abs, H, "uniformoutput", false); Added: trunk/octave-forge/main/control/devel/multiplot2.m =================================================================== --- trunk/octave-forge/main/control/devel/multiplot2.m (rev 0) +++ trunk/octave-forge/main/control/devel/multiplot2.m 2012-09-13 08:09:07 UTC (rev 11001) @@ -0,0 +1,110 @@ +%% -*- texinfo -*- +%% Frequency-weighted controller reduction. + +% =============================================================================== +% Frequency Weighted Controller Reduction Lukas Reichlin December 2011 +% =============================================================================== +% Reference: Madievski, A.G. and Anderson, B.D.O. +% Sampled-Data Controller Reduction Procedure +% IEEE Transactions of Automatic Control +% Vol. 40, No. 11, November 1995 +% =============================================================================== + +% Tabula Rasa +clear all, close all, clc + +% Plant +Ap1 = [ 0.0 1.0 + 0.0 0.0 ]; + +Ap2 = [ -0.015 0.765 + -0.765 -0.015 ]; + +Ap3 = [ -0.028 1.410 + -1.410 -0.028 ]; + +Ap4 = [ -0.04 1.85 + -1.85 -0.04 ]; + +Ap = blkdiag (Ap1, Ap2, Ap3, Ap4); + +Bp = [ 0.026 + -0.251 + 0.033 + -0.886 + -4.017 + 0.145 + 3.604 + 0.280 ]; + +Cp = [ -0.996 -0.105 0.261 0.009 -0.001 -0.043 0.002 -0.026 ]; + +Dp = [ 0.0 ]; + +P = ss (Ap, Bp, Cp, Dp); + +% Controller +Ac = [ -0.4077 0.9741 0.1073 0.0131 0.0023 -0.0186 -0.0003 -0.0098 + -0.0977 -0.1750 0.0215 -0.0896 -0.0260 0.0057 0.0109 -0.0105 + 0.0011 0.0218 -0.0148 0.7769 0.0034 -0.0013 -0.0014 0.0011 + -0.0361 -0.5853 -0.7701 -0.3341 -0.0915 0.0334 0.0378 -0.0290 + -0.1716 -2.6546 -0.0210 -1.4467 -0.4428 1.5611 0.1715 -0.1318 + -0.0020 0.0950 0.0029 0.0523 -1.3950 -0.0338 -0.0062 0.0045 + 0.1607 2.3824 0.0170 1.2979 0.3721 -0.1353 -0.1938 1.9685 + -0.0006 0.1837 0.0048 0.1010 0.0289 -0.0111 -1.8619 -0.0311 ]; + +Bc = [ -0.4105 + -0.0868 + -0.0004 + 0.0036 + 0.0081 + -0.0085 + -0.0004 + -0.0132 ]; + +Cc = [ -0.0447 -0.6611 -0.0047 -0.3601 -0.1033 0.0375 0.0427 -0.0329 ]; + +Dc = [ 0.0 ]; + +K = ss (Ac, Bc, Cc, Dc); + +% Controller Reduction +Kr4 = spaconred (P, K, 4, 'feedback', '-') +Kr2 = spaconred (P, K, 2, 'feedback', '-') + +%{ +% Open Loop +L = P * K; +Lr4 = P * Kr4; +Lr2 = P * Kr2; + +% Closed Loop +T = feedback (L); +Tr4 = feedback (Lr4); +Tr2 = feedback (Lr2); +%} + +% Frequency Range +w = {1e-2, 1e1}; +% w = logspace (-2, 1, 500); + +% Bode Plot of Controller +figure (1) +bode2 (K, Kr4, Kr2, w) +title ('Bode Diagrams of K and Kr') +legend ('K (8 states)', 'Kr (4 states)', 'Kr (2 states)', 'location', 'southwest') + +%{ +% Step Response of Closed Loop +[y, t] = step (T, 100); +[yr4, tr4] = step (Tr4, 100); +[yr2, tr2] = step (Tr2, 100); + +figure (2) +plot (t, y, tr4, yr4, tr2, yr2) +grid ('on') +title ('Step Response of Closed Loop') +xlabel ('Time [s]') +ylabel ('Output [-]') +legend ('K (8 states)', 'Kr (4 states)', 'Kr (2 states)', 'Location', 'SouthEast') +%} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |