fminunc not converging objective function
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1694741/image.jpeg)
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 Kommentar
Torsten
am 14 Mai 2024
Bearbeitet: Torsten
am 14 Mai 2024
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
Akzeptierte Antwort
Matt J
am 14 Mai 2024
Bearbeitet: Matt J
am 14 Mai 2024
You need to a better choice of units for x(3), at least for the optimization step. Below, I modify the objective function so that x(3) is measured in MHz instead of Hz.
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;
s=[1,1,1e6]; %unit scaling
x0 = [0,0,0];
fun = @(x) myfunc1(x.*s, obs, lags, tau);
options = optimoptions('fminunc', 'Display', 'iter', 'StepTolerance', 1e-20, ...
'FunctionTolerance', 1e-9);
[x,fopt] = fminunc(fun, x0,options);
x=x.*s;
x1=x(1),x2=x(2),x3=x(3)
fopt
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
6 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Conditional Mean Models finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!