parafit.m

来自「这是一个用于语音信号处理的工具箱」· M 代码 · 共 35 行

M
35
字号
%FUNCTION PARAFIT finds the parabola polynomial function that fits the given
%         two points.
%         
% [cof,yi]=parafit(x,y,factor,xi);
% INPUT :   [x(1) x(2)] and [y(1) y(2)] are the given two knobs 
%           factor == 1 set the parabola max/min at (x1,y1)
%                       otherwise set the parabola max/min at (x2,y2)
%           xi == new abscissa vector
%             
% OUTPUT :   cof == the coefficients that describe the cubic polynomial 
%             yi == the corresponding vector to xi

%
%       where  y= cof(1)*x^2+cof(2)*x+cof(3)

function [cof,yi]=parafit(x,y,factor,xi)

x1=x(1);  x2=x(2);
y1=y(1);  y2=y(2);

if factor==1   %% y=a*(x-x1)^2+y1

     a=(y2-y1)/(x1-x2)/(x1-x2);
     cof=[a -2*a*x1 a*x1*x1+y1];

else           %% y=a*(x-x2)^2+y2

     a=(y1-y2)/(x1-x2)/(x1-x2);
     cof=[a -2*a*x2 a*x2*x2+y2];
end

if nargout>1
     yi=polyval(cof,xi);
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?