fminunc not converging objective function
Afficher commentaires plus anciens
I'm trying to minimize the following from observations data (which now is synthetic):
Observation generation:
Fs = 80E6;
lags = (-10:10)';
tau = lags/Fs;
bw = 0.1;
[obs, obs_A, obs_C] = Raa_parabola(lags, bw);
function [y, A, C] = Raa_parabola(lags,bw)
%RAA_PARABOLA generates a parabola function given a lag vector.
% tau: time vector
% bw: bandwidth at RF
x2 = 1/bw;
x1 = -x2;
A = 1/x1/x2;
B = 0;
C = A*x1*x2;
y = A*lags.^2 + B*lags + C;
end
Which generates a parabola given a tau vector and a bandwidth bw (Fig. 1)

Adding phase to this observations:
f = 420E3;
ph = exp(1j*2*pi*f*tau);
obs = obs.*ph;
Thus the objective function will have 2 parabola parameters and 1 last parameter to obtain the phase, defined as:
function F = myfunc1(x, o, lags, tau)
m_mag = x(1)*lags.^2 + x(2); % magnitude
m_phase = exp(1j*2*pi*x(3)*tau); % phase
m = m_mag.*m_phase; % model
e = m - o; % error = model - observations
F = e'*e; % mean square error
end
With the idea to generate a kinda least squares minimization and use F as the mean square error.
x0 = [0,0,0];
fun = @(x) myfunc1(x, obs, lags, tau);
options = optimoptions('fminunc', 'Display', 'iter', 'StepTolerance', 1e-20, 'FunctionTolerance', 1e-9, ...
'MaxFunctionEvaluations', 300, 'DiffMinChange', 1e-5);
[x,fopt] = fminunc(fun, x0,options);
fprintf("Observation coefficients: A = %.2f, C = %.2f\n",obs_A,obs_C)
disp(x);
y = x(1)*lags.^2 + x(2);
y = y.*exp(1j*2*pi*x(3)*tau);
figure(1); clf;
subplot(4,1,1); plot(lags,real(obs),'LineWidth',2);hold on;
subplot(4,1,2); plot(lags,imag(obs),'LineWidth',2);hold on;
subplot(4,1,3); plot(lags,abs(obs),'LineWidth',2);hold on;
subplot(4,1,4); plot(lags,angle(obs)*180/pi,'LineWidth',2);hold on;
subplot(4,1,1); plot(lags,real(y),'LineWidth',1.5); legend('Obs','Model');
subplot(4,1,2); plot(lags,imag(y),'LineWidth',1.5); legend('Obs','Model');
subplot(4,1,3); plot(lags,abs(y),'LineWidth',2);hold on;
subplot(4,1,4); plot(lags,angle(y)*180/pi,'LineWidth',2);hold on;
Notice that values x(1) and x(2) converge to a valid point (for me) but parameter 3 should be 420E3.
Where is my misconception?
Thank you very much.
1 commentaire
Fs = 80E6;
lags = (-10:10)';
tau = lags/Fs;
bw = 0.1;
[obs, obs_A, obs_C] = Raa_parabola(lags, bw);
f = 420E3;
ph = exp(1j*2*pi*f*tau);
obs = obs.*ph;
x0 = [0,0,0];
fun = @(x) myfunc1(x, obs, lags, tau);
options = optimoptions('fminunc', 'Display', 'iter', 'StepTolerance', 1e-20, 'FunctionTolerance', 1e-9, ...
'MaxFunctionEvaluations', 300, 'DiffMinChange', 1e-5);
[x,fopt] = fminunc(fun, x0,options)
fprintf("Observation coefficients: A = %.2f, C = %.2f\n",obs_A,obs_C)
y = x(1)*lags.^2 + x(2);
y = y.*exp(1j*2*pi*x(3)*tau);
figure(1); clf;
subplot(4,1,1); plot(lags,real(obs),'LineWidth',2);hold on;
subplot(4,1,2); plot(lags,imag(obs),'LineWidth',2);hold on;
subplot(4,1,3); plot(lags,abs(obs),'LineWidth',2);hold on;
subplot(4,1,4); plot(lags,angle(obs)*180/pi,'LineWidth',2);hold on;
subplot(4,1,1); plot(lags,real(y),'LineWidth',1.5); legend('Obs','Model');
subplot(4,1,2); plot(lags,imag(y),'LineWidth',1.5); legend('Obs','Model');
subplot(4,1,3); plot(lags,abs(y),'LineWidth',2);hold on;
subplot(4,1,4); plot(lags,angle(y)*180/pi,'LineWidth',2);hold on;
function [y, A, C] = Raa_parabola(lags,bw)
%RAA_PARABOLA generates a parabola function given a lag vector.
% tau: time vector
% bw: bandwidth at RF
x2 = 1/bw;
x1 = -x2;
A = 1/x1/x2;
B = 0;
C = A*x1*x2;
y = A*lags.^2 + B*lags + C;
end
function F = myfunc1(x, o, lags, tau)
m_mag = x(1)*lags.^2 + x(2); % magnitude
m_phase = exp(1j*2*pi*x(3)*tau); % phase
m = m_mag.*m_phase; % model
e = m - o; % error = model - observations
F = e'*e; % mean square error
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

