怎样在MATLAB中划出一个函数的包络线

如题所述

下面是一系列关于MATLAB的包络线的程序:
%这是定义了一个函数:
function [up,down] = envelope(x,y,interpMethod)

%ENVELOPE gets the data of upper and down envelope of the known input (x,y).
%
% Input parameters:
% x the abscissa of the given data
% y the ordinate of the given data
% interpMethod the interpolation method
%
% Output parameters:
% up the upper envelope, which has the same length as x.
% down the down envelope, which has the same length as x.
%
% See also DIFF INTERP1

% Designed by: Lei Wang, , 11-Mar-2003.
% Last Revision: 21-Mar-2003.
% Dept. Mechanical & Aerospace Engineering, NC State University.
% $Revision: 1.1 $ $Date: 3/21/2003 10:33 AM $

if length(x) ~= length(y)
error('Two input data should have the same length.');
end

if (nargin < 2)|(nargin > 3),
error('Please see help for INPUT DATA.');
elseif (nargin == 2)
interpMethod = 'linear';
end

% Find the extreme maxim values
% and the corresponding indexes
%----------------------------------------------------
extrMaxValue = y(find(diff(sign(diff(y)))==-2)+1);
extrMaxIndex = find(diff(sign(diff(y)))==-2)+1;

% Find the extreme minim values
% and the corresponding indexes
%----------------------------------------------------
extrMinValue = y(find(diff(sign(diff(y)))==+2)+1);
extrMinIndex = find(diff(sign(diff(y)))==+2)+1;

up = extrMaxValue;
up_x = x(extrMaxIndex);

down = extrMinValue;
down_x = x(extrMinIndex);

% Interpolation of the upper/down envelope data
%----------------------------------------------------
up = interp1(up_x,up,x,interpMethod);
down = interp1(down_x,down,x,interpMethod);
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-01
下面的实例,可以看看,求包络的时候暂时没有考虑边界条件,自己可以完善:
fs=30;
t=0:1/fs:200;
x6=sin(2*pi*2*t)+sin(2*pi*4*t);
plot(t,x6);
xlim([0 5])
hold on
d = diff(x6);
n = length(d);
d1 = d(1:n-1);
d2 = d(2:n);
indmin = find(d1.*d2<0 & d1<0)+1;
indmax = find(d1.*d2<0 & d1>0)+1;
envmin = spline(t(indmin),x6(indmin),t);
envmax = spline(t(indmax),x6(indmax),t);
plot(t,envmin,'r');
plot(t,envmax,'m');本回答被网友采纳
第2个回答  2012-02-28
这个函数是二维函数还是三维函数啊,若是二维直接用plot就可以画函数曲线了 三维函数也有画三维的函数
第3个回答  2012-03-01
可以先通过求导找出极点,然后对极点进行函数拟合.
思路是这样.具体的代码,你懂的.....追问

呵呵 具体点行不?

追答

呵呵,具体的函数我也忘记了....你好好的找一下吧

本回答被网友采纳
相似回答