📄 optmiz2.cpp
字号:
//
// File = optmiz2.cpp
//
#include <math.h>
#include "optmiz2.h"
#include "goldsrh2.h"
void optimize2( FreqSampFilterSpec *filter_spec,
FreqSampFilterDesign *filter_design,
FreqSampFilterResponse *filter_resp,
double y_base_init,
double tol,
double tweak_factor,
double rectComps[])
{
double x1, x2, x3, y3, min_func_val;
double slopes[5], origins[5];
double old_min, x_max;
double y_base;
double rho_min, rho_max;
y_base = y_base_init;
old_min = 9999.0;
for(;;)
{
//---------------------------------------------------
// do starting point for new steepest descent line
slopes[1] = 1.0;
slopes[2] = 0.0;
origins[1] = 0.0;
origins[2] = y_base;
rho_min = 0.0;
rho_max = 1.0;
x1 = GoldenSearch2( tol,
filter_spec,
filter_design,
filter_resp,
rho_min,
rho_max,
origins,
slopes,
&min_func_val);
/*-------------------------------------*/
/* do perturbed point to get */
/* slope for steepest descent line */
origins[2]=y_base * tweak_factor;
x2 = GoldenSearch2( tol,
filter_spec,
filter_design,
filter_resp,
rho_min,
rho_max,
origins,
slopes,
&min_func_val);
/*-------------------------------------*/
/* define line of steepest descent */
/* and find optimal point along line */
slopes[2] = y_base*(1-tweak_factor)/(x1-x2);
origins[2] = y_base - slopes[2] * x1;
x_max = (1.0 - origins[2])/slopes[2];
x3 = GoldenSearch2( tol,
filter_spec,
filter_design,
filter_resp,
rho_min,
x_max,
origins,
slopes,
&min_func_val);
y3=origins[2] + x3 * slopes[2];
/*---------------------------------------------------------------*/
/* if ripple at best point on current line is within specified */
/* tolerance of ripple at best point on previous line, */
/* then stop; otherwise stay in loop and define a new line */
/* starting at the best point on line just completed. */
if(fabs(old_min-min_func_val) < tol) break;
old_min = min_func_val;
y_base = y3;
}
rectComps[0] = x3;
rectComps[1] = origins[2] + x3 * slopes[2];
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -