📄 drydemo.html
字号:
<!--This HTML is auto-generated from an m-file.Your changes will be overwritten.--><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium;">Overview</p><ul xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"><li><a href="#Nonlinear system identification">Nonlinear system identification</a></li></ul><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;">Nonlinear system identification<a name="Nonlinear system identification"></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">This demo addresses the use of ANFIS function in the Fuzzy LogicToolbox for nonlinear dynamical system identification. This demo alsorequires the System Identification Toolbox, as a comparison is madebetween a nonlinear ANFIS and a linear ARX model.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Copyright 1994-2002 The MathWorks, Inc.$Revision: 1.9 $</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px"><span style="color:green">% Exit if the IDENT toolbox is not on the path</span><span style="color:blue">if</span> exist(<span style="color:#B20000">'arx.m'</span>,<span style="color:#B20000">'file'</span>) == 0 errordlg(<span style="color:#B20000">'DRYDEMO requires the System Identification Toolbox.'</span>); <span style="color:blue">return</span>;<span style="color:blue">end</span></pre><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The data set for ANFIS and ARX modeling was obtained from a laboratorydevice called Feedback's Process Trainer PT 326, as described in Chapter17 of Prof. Lennart Ljung's book "System Identification, Theory for theUser", Prentice-Hall, 1987. The device's function is like a hair dryer:air is fanned through a tube and heated at the inlet. The air temperatureis measure by a thermocouple at the outlet. The input u(k) is the voltageover a mesh of resistor wires to heat incoming air; the output y(k) isthe outlet air temperature. Here is a the system model</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">a=imread(<span style="color:#B20000">'dryblock.jpg'</span>, <span style="color:#B20000">'jpg'</span>);image(a); axis image;axis off;</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="drydemo_img02.gif"><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Here are the results of the test.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">load dryer2;data_n = length(y2);output = y2;input = [[0; y2(1:data_n-1)] <span style="color:blue">...</span> [0; 0; y2(1:data_n-2)] <span style="color:blue">...</span> [0; 0; 0; y2(1:data_n-3)] <span style="color:blue">...</span> [0; 0; 0; 0; y2(1:data_n-4)] <span style="color:blue">...</span> [0; u2(1:data_n-1)] <span style="color:blue">...</span> [0; 0; u2(1:data_n-2)] <span style="color:blue">...</span> [0; 0; 0; u2(1:data_n-3)] <span style="color:blue">...</span> [0; 0; 0; 0; u2(1:data_n-4)] <span style="color:blue">...</span> [0; 0; 0; 0; 0; u2(1:data_n-5)] <span style="color:blue">...</span> [0; 0; 0; 0; 0; 0; u2(1:data_n-6)]];data = [input output];data(1:6, :) = [];input_name = str2mat(<span style="color:#B20000">'y(k-1)'</span>,<span style="color:#B20000">'y(k-2)'</span>,<span style="color:#B20000">'y(k-3)'</span>,<span style="color:#B20000">'y(k-4)'</span>,<span style="color:#B20000">'u(k-1)'</span>,<span style="color:#B20000">'u(k-2)'</span>,<span style="color:#B20000">'u(k-3)'</span>,<span style="color:#B20000">'u(k-4)'</span>,<span style="color:#B20000">'u(k-5)'</span>,<span style="color:#B20000">'u(k-6)'</span>);trn_data_n = 300;index = 1:100;subplot(2,1,1);plot(index, y2(index), <span style="color:#B20000">'-'</span>, index, y2(index), <span style="color:#B20000">'o'</span>);ylabel(<span style="color:#B20000">'y(k)'</span>);subplot(2,1,2);plot(index, u2(index), <span style="color:#B20000">'-'</span>, index, u2(index), <span style="color:#B20000">'o'</span>);ylabel(<span style="color:#B20000">'u(k)'</span>);</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="drydemo_img03.gif"><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The data points was collected at a sampling time of 0.08 second. Onethousand input-output data points were collected from the process as theinput u(k) was chosen to be a binary random signal shifting between 3.41and 6.41 V. The probability of shifting the input at each sample was 0.2.The data set is available from the System Identification Toolbox; and theabove plots show the output temperature y(k) and input voltage u(t) forthe first 100 time steps.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">A conventional method is to remove the means from the data and assume alinear model of the form:</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">y(k)+a1*y(k-1)+...+am*y(k-m)=b1*u(k-d)+...+bn*u(k-d-n+1)</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">where ai (i = 1 to m) and bj (j = 1 to n) are linear parameters to bedetermined by least-squares methods. This structure is called the ARXmodel and it is exactly specified by three integers [m, n, d]. To find anARX model for the dryer device, the data set was divided into a training(k = 1 to 300) and a checking (k = 301 to 600) set. An exhaustive searchwas performed to find the best combination of [m, n, d], where each ofthe integer is allowed to changed from 1 to 10 independently. The bestARX model thus found is specified by [m, n, d] = [5, 10, 2], with atraining RMSE of 0.1122 and a checking RMSE of 0.0749. The above figuredemonstrates the fitting results of the best ARX model.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">trn_data_n = 300;total_data_n = 600;z = [y2 u2];z = dtrend(z);ave = mean(y2);ze = z(1:trn_data_n, :);zv = z(trn_data_n+1:total_data_n, :);T = 0.08;<span style="color:green">% Run through all different models</span>V = arxstruc(ze, zv, struc(1:10, 1:10, 1:10));<span style="color:green">% Find the best model</span>nn = selstruc(V, 0);<span style="color:green">% Time domain plot</span>th = arx(ze, nn);th = sett(th, 0.08);u = z(:, 2);y = z(:, 1)+ave;yp = idsim(u, th)+ave;xlbl = <span style="color:#B20000">'Time Steps'</span>;subplot(2,1,1); index = 1:trn_data_n;plot(index, y(index), index, yp(index), <span style="color:#B20000">'.'</span>);rmse = norm(y(index)-yp(index))/sqrt(length(index));title([<span style="color:#B20000">'(a) Training Data (Solid Line) and ARX Prediction (Dots) with RMSE = '</span> num2str(rmse)]);disp([<span style="color:#B20000">'[na nb d] = '</span> num2str(nn)]);xlabel(xlbl);subplot(2,1,2); index = (trn_data_n+1):(total_data_n);plot(index, y(index), index, yp(index), <span style="color:#B20000">'.'</span>);rmse = norm(y(index)-yp(index))/sqrt(length(index));title([<span style="color:#B20000">'(b) Checking Data (Solid Line) and ARX Prediction (Dots) with RMSE = '</span> num2str(rmse)]);xlabel(xlbl);</pre><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:gray; font-style:italic;">[na nb d] = 5 10 2</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="drydemo_img05.gif"><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The ARX model is inherently linear and the most significant advantage isthat we can perform model structure and parameter identification rapidly.The performance in the above plots appear to be satisfactory. However, ifa better performance level is desired, we might want to resort to anonlinear model. In particular, we are going to use a neuro-fuzzymodeling approach, ANFIS, to see if we can push the performance level byusing a fuzzy inference system.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">To use ANFIS for system identification, the first thing we need to do isinput selection. That is, to determine which variables should be theinput arguments to an ANFIS model. For simplicity, we suppose that thereare 10 input candidates (y(k-1), y(k-2), y(k-3), y(k-4), u(k-1), u(k-2),u(k-3), u(k-4), u(k-5), u(k-6)), and the output to be predicted is y(k).A heuristic approach to input selection is called sequential forwardsearch, in which each input is selected sequentially to optimize thetotal squared error. This can be done by the function seqsrch; the resultis shown in the above plot, where 3 inputs (y(k-1), u(k-3), and u(k-4))are selected with a training RMSE of 0.0609 and checking RMSE of 0.0604.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">trn_data_n = 300;trn_data = data(1:trn_data_n, :);chk_data = data(trn_data_n+1:trn_data_n+300, :);[input_index, elapsed_time]=seqsrch(3, trn_data, chk_data, input_name);fprintf(<span style="color:#B20000">'\nElapsed time = %f\n'</span>, elapsed_time);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -