美文网首页
MATLAB|绘制曲线包络

MATLAB|绘制曲线包络

作者: 冰冻生菜ch | 来源:发表于2018-03-22 00:11 被阅读133次

别人的绘制曲线包络的程序。

from:http://www.ilovematlab.cn/thread-18145-1-1.html

Mydefinition_envelope(x,y,interpMethod)

程序

function  [up,down]=Mydefinition_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, <WangLeiBox@hotmail.com>, 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);

用法

clc;

% Load a signal waveform
%--------------------------------------------
N = 100;
fs = 50;
t = ((1:N)/512)';
T0 = 0.01;
f0 = 12.7;
T1 = 0.026;
f1 = 35.8
y = exp(-T0*t) .* 5 .* sin(2*pi * f0*t) + exp(-T1*t).*4.*sin(2*pi*f1*t);
%load data.txt data;
%t = data(:,1); % time series
%y = data(:,2); % signal data
figure(1);
plot(t,y,'b-');
title('The original signal waveform','FontSize',18);



% Call function envelope to
% obtain the envelope data
%--------------------------------------------
[up,down] = envelope(t,y,'linear');



% Show the envelope alone
%--------------------------------------------
figure(2)
plot(t,up); hold on;
plot(t,down);
title('The envelope of the given signal data','FontSize',18);
hold off;



% Show the original signal and its envelope
%--------------------------------------------
figure(3)
plot(t,y,'g-'); hold on;
plot(t,up,'r-.');
plot(t,down,'r-.');
title('The envelope vs the given signal data','FontSize',18);
hold off;

相关文章

  • MATLAB|绘制曲线包络

    别人的绘制曲线包络的程序。 from:http://www.ilovematlab.cn/thread-18145...

  • Matlab 如何绘制复杂曲线的包络线

    [TOC] 1.处理前后的效果对比,图示为某声波傅里叶变换(fft)后的频谱图。 2.原数据为横纵坐标为 freq...

  • Matlab基本绘图

    matlab基本绘图指令 plot 函数的基本使用语法格式为: 绘制一条曲线:plot(xdata, ydata,...

  • 遗传算法案例代码注解【转】

    本代码采用matlab编写: %% I. 清空环境变量 clear all clc %% II. 绘制函数曲线 x...

  • Matplotlib绘制动态实时曲线的方法改进

    很多时候,我们需要实时的绘制曲线,如实时的绘制串口接收到的数据。最先想到的解决策略是类似于Matlab种的draw...

  • MATLAB用不同颜色绘制多条曲线

    在我们的学习工作中,为了直观、数据的比较及趋势的分析等,我们往往需要在一张图片中用不同的颜色绘制多条曲线。这篇文章...

  • matplotlib作图

    类MATLAB API 加载方式from pylab import * 图形绘制与matlab相似 matplot...

  • MATLAB绘制双刻度曲线图

    数据:这里准备的是两个相同维度的行向量~ 主要用于刻画一个对象在不同标准的测量值,最终绘制的双刻度曲线图如下所示:...

  • bar

    matlab中函数bar绘制直方图中的应用函数bar(x)可以绘制直方图

  • PPT版式设计第18期:PPT中的曲线设计

    今天和大家聊聊PPT中的曲线设计。 上图中的曲线是用PPT绘制的,也是本例设计的重点技能,曲线弧形的绘制,那绘制这...

网友评论

      本文标题:MATLAB|绘制曲线包络

      本文链接:https://www.haomeiwen.com/subject/fxppixtx.html