ML_Feedback_arb

PURPOSE ^

Single-input, single-output discrete-time system operating in unity feedback

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Single-input, single-output discrete-time system operating in unity feedback
 excited by a random input. The transient is removed by the local polynomial method 
 via the function "ArbLocalPolyAnal".
 A comparison is made between the estimate with and without reference signal. 
 Known input, noisy output case (generalized output error) 

 Rik Pintelon, 12 October 2011

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %
0002 % Single-input, single-output discrete-time system operating in unity feedback
0003 % excited by a random input. The transient is removed by the local polynomial method
0004 % via the function "ArbLocalPolyAnal".
0005 % A comparison is made between the estimate with and without reference signal.
0006 % Known input, noisy output case (generalized output error)
0007 %
0008 % Rik Pintelon, 12 October 2011
0009 %
0010 
0011 clear all
0012 close all
0013 
0014 
0015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0016 % Definition discrete-time plant and noise models %
0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0018 
0019 % definition discrete-time plant model
0020 B = 0.5*[0 1 0.5]; 
0021 A = [1 -1.5 0.7];
0022 
0023 % definition discrete-time noise model
0024 C = 0.1*[1 -1 0.9];
0025 D = [1 -0.2 0.5];
0026 
0027 N = 8000;               % number of time domain points
0028 Ts = 1;
0029 fs = 1/Ts;              % sampling frequency
0030 
0031 
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 % Set the default values for the parametric identification %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 
0036 na = length(A)-1;       % denominator order plant model
0037 nb = length(B)-1;       % numerator order plant model
0038 nu = 1;                 % number of inputs
0039 ny = 1;                 % number of outputs
0040 PlantPlane = 'z';       % discrete-time model
0041 [Sel, Theta0, ModelVar, IterVar] = MIMO_ML_DefaultValues(na, nb, nu, ny, PlantPlane);
0042 Theta0.A = A;
0043 Theta0.B(1,1,:) = B;
0044 
0045 
0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0047 % Simulation known input - noisy output data %
0048 % of the system operating in unity feedback  %
0049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0050 
0051 % reference signal
0052 r = rand(1, N);
0053 
0054 % deterministic part input and output
0055 u0 = filter(A, A+B, r);
0056 y0 = filter(B, A+B, r);
0057 
0058 % noisy part input and output
0059 stde = 4;                       % value chosen such that value std(v) ~ std(u0)
0060 e = stde*randn(1, N);
0061 v = filter(conv(C, A), conv(D, A+B), e);
0062 
0063 % known input, noisy output
0064 u = u0 - v;
0065 y = y0 + v;
0066 
0067 
0068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0069 % Calling the ArbLocalPolyAnal function %
0070 % case 1: reference signal is known     %
0071 %         => errors-in-variables        %
0072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0073 
0074 % data
0075 data1.u = u;                             % row index is the input number; the column index the time instant (in samples)
0076 data1.y = y;                             % row index is the output number; the column index the time instant (in samples)
0077 data1.r = r;                             % the reference signal is needed to obtain consistent nonparametric FRF estimates in feedback
0078 data1.Ts = 1/fs;                         % sampling period
0079 
0080 % method
0081 method.dof = 6;                         % degrees of freedom of the variance estimate
0082 method.order = 2;                       % order local polynomial approximation
0083 
0084 % local polynomial estimate FRF and its variance
0085 [CZ1, Z1, freq, G1, CvecG1, dof1, CL1] = ArbLocalPolyAnal(data1, method);
0086 
0087 
0088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0089 % Calling the ArbLocalPolyAnal function %
0090 % case 2: no reference available        %
0091 %         => generalized output error   %
0092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0093 
0094 % data
0095 data2.u = u;                             % row index is the input number; the column index the time instant (in samples)
0096 data2.y = y;                             % row index is the output number; the column index the time instant (in samples)
0097 data2.Ts = 1/fs;                         % sampling period
0098 
0099 % method
0100 method.dof = 6;                         % degrees of freedom of the variance estimate
0101 method.order = 2;                       % order local polynomial approximation
0102 
0103 % local polynomial estimate FRF and its variance
0104 [CZ2, Z2, freq, G2, CvecG2, dof2, CL2] = ArbLocalPolyAnal(data2, method);
0105 
0106 
0107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0108 % Data for identification           %
0109 % case 1: reference signal is known %
0110 %         => errors-in-variables    %
0111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0112 
0113 data_fit1.Y = Z1.m_nt(1:ny,:);            % sample mean with transient removal
0114 data_fit1.U = Z1.m_nt(ny+1:end,:);        % noiseless input DFT spectrum
0115 data_fit1.freq = freq;
0116 data_fit1.Ts = 1/fs;
0117 data_fit1.CY = CZ1.m_nt(1:ny,1:ny,:);     % sample covariance sample mean with transient removal
0118 data_fit1.CU = CZ1.m_nt(ny+1:end,ny+1:end,:);
0119 data_fit1.CYU = CZ1.m_nt(1:ny,ny+1:end,:);
0120 
0121 
0122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0123 % Data for identification               %
0124 % case 2: no reference signal available %
0125 %         => generalized output error   %
0126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0127 
0128 data_fit2.Y = Z2.m_nt(1:ny,:);            % sample mean with transient removal
0129 data_fit2.U = Z2.m_nt(ny+1:end,:);        % noiseless input DFT spectrum
0130 data_fit2.freq = freq;
0131 data_fit2.Ts = 1/fs;
0132 data_fit2.CY = CZ2.m_nt(1:ny,1:ny,:);     % sample covariance sample mean with transient removal
0133 data_fit2.CU = CZ2.m_nt(ny+1:end,ny+1:end,:);
0134 data_fit2.CYU = CZ2.m_nt(1:ny,ny+1:end,:);
0135 
0136 
0137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0138 % Parametric estimate plant model   %
0139 % case 1: reference signal is known %
0140 %         => errors-in-variables    %
0141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0142 
0143 % starting values plant model
0144 data_fit1.W = data_fit1.CY;
0145 [ThetaWTLS1, smax, smin, wscale] = MIMO_WTLS(data_fit1, Sel, ModelVar);
0146 [ThetaIQML1, CostIQML1, smax, smin, wscale] = MIMO_IQML(data_fit1, Sel, ThetaWTLS1, ModelVar, IterVar);
0147 
0148 % SML estimate
0149 [ThetaML1, CostML1, smax, smin, wscale] = MIMO_ML(data_fit1, Sel, ThetaIQML1, ModelVar, IterVar);
0150 
0151 
0152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0153 % Parametric estimate plant model     %
0154 % case 2: reference signal is known   %
0155 %         => generalized output error %
0156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0157 
0158 % starting values plant model
0159 data_fit2.W = data_fit2.CY;
0160 [ThetaWTLS2, smax, smin, wscale] = MIMO_WTLS(data_fit2, Sel, ModelVar);
0161 [ThetaIQML2, CostIQML2, smax, smin, wscale] = MIMO_IQML(data_fit2, Sel, ThetaWTLS2, ModelVar, IterVar);
0162 
0163 % SML estimate
0164 [ThetaML2, CostML2, smax, smin, wscale] = MIMO_ML(data_fit2, Sel, ThetaIQML2, ModelVar, IterVar);
0165 
0166 
0167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0168 % Cramer-Rao lower bound            %
0169 % case 1: reference signal is known %
0170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0171 
0172 data_fit1.dof = dof1;                     % the CR-bound needs variability of the estimated noise covariance
0173 data_fit1.CY = CZ1.n(1:ny,1:ny,:);        % the CR-bound requires the noise covariance; not the covariance of the sample mean
0174 data_fit1.CU = CZ1.n(ny+1:end,ny+1:end,:);
0175 data_fit1.CYU = CZ1.n(1:ny,ny+1:end,:);
0176 
0177 % Calculation parametric TF model and its covariance; the poles (+ resonance frequency, damping, time constant) and their covariances;
0178 % and residue matrices (+ singular values and left and right singular vectors) and their covariances
0179 [CRbound1, GML1, ThetaML1] = MIMO_ML_CRbound(data_fit1, Sel, ThetaML1, ModelVar);
0180 
0181 GML1 = squeeze(GML1);
0182 varGML1 = squeeze(CRbound1.vecG);
0183 
0184 
0185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0186 % Cramer-Rao lower bound                %
0187 % case 2: no reference signal available %
0188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0189 
0190 data_fit2.dof = dof1;                     % the CR-bound needs variability of the estimated noise covariance
0191 data_fit2.CY = CZ2.n(1:ny,1:ny,:);        % the CR-bound requires the noise covariance; not the covariance of the sample mean
0192 data_fit2.CU = CZ2.n(ny+1:end,ny+1:end,:);
0193 data_fit2.CYU = CZ2.n(1:ny,ny+1:end,:);
0194 
0195 % Calculation parametric TF model and its covariance; the poles (+ resonance frequency, damping, time constant) and their covariances;
0196 % and residue matrices (+ singular values and left and right singular vectors) and their covariances
0197 [CRbound2, GML2, ThetaML2] = MIMO_ML_CRbound(data_fit2, Sel, ThetaML2, ModelVar);
0198 
0199 GML2 = squeeze(GML2);
0200 varGML2 = squeeze(CRbound2.vecG);
0201 
0202 
0203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0204 % Calculation true plant model and noise variances %
0205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0206 
0207 % true FRF
0208 q = exp(-sqrt(-1)*2*pi*freq/fs);        % z^(-1) as a function of the frequency
0209 G0 = polyval(fliplr(B), q) ./ polyval(fliplr(A), q);
0210 G0 = G0.';
0211 
0212 % true noise model
0213 H0 = stde*polyval(fliplr(C), q) ./ polyval(fliplr(D), q);
0214 H0 = H0.';
0215 
0216 % true input-output variances for case 1
0217 varVu_0 = abs((H0./(1+G0)).^2).';                     % true input noise variance
0218 varVy_0 = abs((H0./(1+G0)).^2).';                     % true output noise variance
0219 
0220 % true output variance for case 2
0221 varY0 = abs(H0.^2).';
0222 
0223 
0224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0225 % Calculation true poles, resonance frequencies, %
0226 % damping ratios, time constants                 %
0227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0228 
0229 % the covariance has no meaning here
0230 [CovPoles0, Poles0] = CovRoots(Theta0.A, eye(na+1), Sel.A, PlantPlane, Ts);
0231 
0232 
0233 %%%%%%%%%%%%%%%%%%%%
0234 % Plot the results %
0235 %%%%%%%%%%%%%%%%%%%%
0236 
0237 % case 1: nonparametric estimates input-output noise variances
0238 varVy = squeeze(CZ1.n(1,1,:));           % estimate output noise variance
0239 varVu = squeeze(CZ1.n(2,2,:));           % estimate input noise variance
0240 
0241 % case 2: nonparametric estimates output noise variance
0242 varY = squeeze(CZ2.n(1,1,:)); 
0243 
0244 % comparison true and estimated input-output noise variances
0245 figure(1)
0246 subplot(211)
0247 plot(freq, db(varVu)/2, 'r', freq, db(varVu_0)/2, 'k');
0248 xlabel('Frequency (Hz)')
0249 ylabel('Input variance (dB)')
0250 title('Reference signal available: EIV solution');
0251 legend('variance estimate', 'true variance', 'Location', 'EastOutside');
0252 subplot(212)
0253 plot(freq, db(varVy)/2, 'r', freq, db(varVy_0)/2, 'k');
0254 xlabel('Frequency (Hz)')
0255 ylabel('Output variance (dB)')
0256 legend('variance estimate', 'true variance', 'Location', 'EastOutside');
0257 zoom on;
0258 shg
0259 
0260 % comparison true plant model and parametric estimate
0261 figure(2)
0262 plot(freq, db(GML1), 'r', freq, db(G0), 'k', freq, db(GML1-G0), 'k--', ...
0263      freq, db(varGML1)/2, 'r--')
0264 xlabel('Frequency (Hz)')
0265 ylabel('Amplitude (dB)')
0266 legend('G-estimate', 'G_0', '|G-G_0|', 'var(G)', 'Location', 'EastOutside');
0267 title('Reference signal available: EIV solution');
0268 zoom on;
0269 shg
0270 
0271 % comparison true and estimated input-output noise variances
0272 figure(3)
0273 plot(freq, db(varY)/2, 'r', freq, db(varY0)/2, 'k');
0274 xlabel('Frequency (Hz)')
0275 ylabel('Output variance (dB)')
0276 title('No reference available: generalized OE solution');
0277 legend('variance estimate', 'true variance', 'Location', 'EastOutside');
0278 zoom on;
0279 shg
0280 
0281 % comparison true plant model and parametric estimate
0282 figure(4)
0283 plot(freq, db(GML2), 'r', freq, db(G0), 'k', freq, db(GML2-G0), 'k--', ...
0284      freq, db(varGML2)/2, 'r--')
0285 xlabel('Frequency (Hz)')
0286 ylabel('Amplitude (dB)')
0287 legend('G-estimate', 'G_0', '|G-G_0|', 'var(G)', 'Location', 'EastOutside');
0288 title('No reference signal available: generalized OE solution');
0289 zoom on;
0290 shg
0291 
0292 F = length(freq);   % number of frequencies
0293 ntheta = sum(Sel.A)+sum(sum(sum(Sel.B))+sum(sum(Sel.Ig))) - 1;
0294 Cost0 = dof1/(dof1-ny)*ny*(F-ntheta/2);
0295 stdCost0 = sqrt(3*(dof1)^3*ny/(dof1-ny)^2/(dof1-ny-1)*(F-ntheta/2));
0296 disp(['Expected value true cost, std true cost, and actual value cost: ',num2str(Cost0),', ',num2str(stdCost0),', and ',num2str(CostML1)]);
0297 
0298 % comparison true and estimated resonance frequencies: case 1, known reference signal
0299 disp('Estimates with reference signal')
0300 disp('Estim. f0 [Hz], std(f0) [Hz], estim. - true [Hz]')
0301 [ThetaML1.poles.freq, CRbound1.poles.freq.^0.5, ThetaML1.poles.freq-Poles0.freq]
0302 
0303 % comparison true and estimated damping ratios: case 1, known reference signal
0304 disp('Estim. damping, std(damping), estim. - true')
0305 [ThetaML1.poles.damp, CRbound1.poles.damp.^0.5, ThetaML1.poles.damp-Poles0.damp]
0306

Generated on Thu 07-Jun-2012 11:58:58 by m2html © 2005