optimization task: using fmincon to optimize 2nd order filtering

1 次查看(过去 30 天)
Hey there,
i'ld like to optimize my 2nd order filter parameters/coefficients. i'm refering to a transfer function like this:
. I'm using this transfer function to filter speed values with systematic distortions.
Dependend on values of D i need to differ various step responses :
w0 = 1/T; b = sqrt(1-D^2); % substitutions
if D > 1
T1 = T/(D+sqrt(D^2-1));
T2 = T/(D-sqrt(D^2-1));
ht = @(t) K*( 1 - 1/(T1-T2)*( T1*exp(-1/T1*t) - T2*exp(-1/T2*t) ) );
elseif D == 1
ht = @(t) K*( 1 - (1+1/T*t) .* exp(-1/T*t) );
elseif D >= 0 && D < 1
ht = @(t) K*( 1 - exp(-w0*D*t) .* 1/b .* sin( b*w0*t + acos(D)) ); % (a la wikipedia)
else
sprintf('error in h(t) !!!');
end
So far, if i'm testing on the following speed curve, i vary my paramaters with sliders
This chart is showing exemplary max-throttle rotational speed values of my DUT. My DUT is a 6.5 HP kart on a testbench (no external additional load applicated). Rotational speed is measured in . Negative values result from direction of rotation. At the beginning of the rising speed at rear/drive axle you can see a clearly curve. the more the speed is increasing the / a automatic centrifugal clutch links the engine to the drive shaft. Those upcoming ups and downs starting at 3200 come from pulsating delivered torque of DUT's one-piston-engine. Of course the systematic disturtion's frequency is increasing along the speed.
I do need filtered speed data near "real time", because i have to calculate certain torque load to simulate as a function of speed. Means those values come from measured speeds and derived acceleration. So i need a quick filter hand in hand with maximum smoothing to get satisfying acceleration values and thus satisfying torque loads which are not "bumpy".
If i'm looking at those step responses, mentioned above, i'm getting charts like this:
Now i want to optimize parameters to get a solution with minimum of rise time, minimum of settling time @ e.q. 5% allowed overshoot.
I tried the whole weekend to archieve this, but "bootless".
e. g. i built an objective function stuff like this:
1. put K, D, T in x-vector
2. aim t_settle as "to minimize" return value of objective function objectiveStepResponse
3. calculate h(t) depending on D
4. calculate time thresholds t25, t75 % of end value (unused so far)
calculate rising time tRise and settling time tSettle
5. return settling time
function [tSettle] = objectiveStepResp(x) % is aimed to be the actually objective function
% variables/parameters:
K = x(1); D = x(2); T = x(3); % given by function parameter x
Amp0 = -6000; dt = 0.01; t = (0:dt:5)'; % given by me =) to characterize the step function
dy = 1/100; % engage tolerance of end value[dec-%] (default: 1 %) % given by me
% calculation cases:
w0 = 1/T; b = sqrt(1-D^2); % substitutions
if D > 1
T1 = T/(D+sqrt(D^2-1)); T2 = T/(D-sqrt(D^2-1));
ht = @(t) K*( 1 - 1/(T1-T2)*( T1*exp(-1/T1*t) - T2*exp(-1/T2*t) ) );
elseif D == 1
ht = @(t) K*( 1 - (1+1/T*t) .* exp(-1/T*t) );
elseif D >= 0 && D < 1
ht = @(t) K*( 1 - exp(-w0*D*t) .* 1/b .* sin( b*w0*t + acos(D)) );
else
sprintf('error @ h(t) !!!');
end
% caluclate final response:
stpResp = Amp0 * ht(t); % calc. scaled step response
% calculate time-parameters:
i = find(abs(stpResp)>abs(stpResp(end)*0.25),1,'first'); % find index of 25 % of end value passing
t25 = t(i); stpResp25 = stpResp(i); % 25 % o.ev.
i = find(abs(stpResp)>abs(stpResp(end)*0.75),1,'first'); % find index of 75 % of end value passing
t75 = t(i); stpResp75 = stpResp(i); % 75 % of ev.
stpResp_dy = abs(stpResp(end)*dy);
iRise = find(abs(stpResp) > abs(stpResp(end)*(1-dy)),1,'first'); % index of 1st 99 % o.ev. passing
iSettle = find((abs(stpResp-stpResp(end)) > abs(dy*stpResp(end))),1,'last'); % index of last 99 % o.ev passing
tRise = t(iRise);
tSettle = t(iSettle); % so far the actually return value
end
Now i have to think about constraints. To begin easily i just wanted to rule:
At the beginning i left away to debug code.
Then i called with most parameters empty:
objective = @(x) objectiveStepResp( x );
x0 = [1 1 0.5]; % initial guesses
disp(['initial Objective: ' num2str(objectiveStepResp(x0)) ]);
A = [];
b = [];
Aeq = [];
beq = [];
lb = [0 0 0];
ub = [2 2 1];
nonlincon = [];
a = fmiccon(objective(x),x0,A,b,Aeq,beq,lb,ub,nonlincon);
disp(a);
disp(['final Objective: ' num2str(objective(x)) ]);
But all in all this is not working. Can anyone help me to minimize my settling time of step respone while optimize parameters ?
edit 1: further removed german notations in figure 1 & 2
Many thanks, Basti

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by