happy 发表于 2006-11-23 16:26

一种有效的包络线算法

本帖最后由 ChaChing 于 2010-9-1 23:43 编辑

function = 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);

happy 发表于 2006-11-23 16:27

本帖最后由 ChaChing 于 2010-9-5 12:09 编辑

使用例子: %DEMOENVELOPE shows how to use function envelope to obtain the
%   upper/down envelope of a given data and plot the envelope.
%
%   See also EVELOPE

%   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:38 AM $

clc;

% Load a signal waveform
%--------------------------------------------
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
%--------------------------------------------
= 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;

qiuqia17 发表于 2007-1-9 10:35

interpMethod 包含几种?
除了 linear

eight 发表于 2007-1-9 10:50

“help interp1”, and you will find it

[ 本帖最后由 ChaChing 于 2010-5-3 00:33 编辑 ]

qiuqia17 发表于 2007-1-10 11:10

本帖最后由 ChaChing 于 2010-9-5 12:25 编辑

我贴
'nearest'Nearest neighbor interpolation
'linear'Linear interpolation (default)
'spline'Cubic spline interpolation
'pchip'Piecewise cubic Hermite interpolation
'cubic'(Same as 'pchip')
'v5cubic'Cubic interpolation used in MATLAB 5. This method does not extrapolate. Also, if x is not equally spaced, 'spline' is used

junzifei 发表于 2008-1-22 22:52

本帖最后由 ChaChing 于 2010-9-5 12:27 编辑

采用hilbert变换也可以
abs(hilbert(x));就可以
不过问题的重点好像不在这里

2365215 发表于 2008-4-24 23:16

有点问题想请教一下

如果x不是单调的怎么办?
我用extrMaxValue = y(find(diff(sign(diff(y)))==-2)+1);
extrMaxIndex = find(diff(sign(diff(y)))==-2)+1;
提取了一下y值,然后再和x一一对应画出的图不是外轮廓线啊

我把图传了一下,请帮我看看。我试着用下轮廓那个做了一下,得到的是一样的图。

上轮廓
extrMaxValue = U2(find(diff(sign(diff(U2(1,:)')))==+2)+1);
extrMaxIndex = find(diff(sign(diff(U2(1,:)')))==+2)+1;

下轮廓
extrMaxValue = U2(find(diff(sign(diff(U2(2,:)')))==-2)+1);
extrMaxIndex = find(diff(sign(diff(U2(2,:)')))==-2)+1;

U2是一个二行1840列的数据

我是这样画图的
for i=1:1840
for j=1:245
if i == extrMaxIndex(j)
plot(Stick(i),extrMaxIndex(j),'.')
end
end
end

sogooda 发表于 2008-4-25 10:37

回复 9楼 的帖子

那就先排序,再做嘛。
doc sort

2365215 发表于 2008-4-25 15:24

本帖最后由 ChaChing 于 2010-9-5 12:22 编辑

谢谢,是我没看懂才会出现问题。 已经搞定。

好像用smooth函数也可以达到类似的效果。(5/12)

ChaChing 发表于 2008-7-2 10:44

首先感谢 Happy教授 !
使用find(diff(sign(diff(y)))==-2)求取极大值的确绝妙
但使用上若有重复点即发生一些小问题如附图
各位大大对如何解决是否有好意见?

zsqlp 发表于 2008-12-31 15:00

你的包络线太精确了,呵呵,有没有一种模糊的啊,画包络线一般就是为了好看,比如区分波包啊之类的,你的有点过头了啊。呵呵

sspitty 发表于 2010-9-1 10:47

matlab好像有个自带的啊 效果看上去还要好~~有没有那代码????

impulse 发表于 2010-9-1 20:21

matlab很容易实现,但一般在做包络时先要对信号进行滤波,最近研究LabVIEW声学振动包时才知道的。

ChaChing 发表于 2010-9-5 12:29

本帖最后由 ChaChing 于 2010-9-5 12:31 编辑

回复 sspitty 的帖子
"matlab好像有个自带的", 那个函数?:@)

回复 junzifei 的帖子
"abs(hilbert(x));就可以", 建议说清楚些! :@)   

禾木目 发表于 2010-11-17 00:16

这程序如果是曲线上升的,得到的包络线就不对了呀
页: [1] 2 3
查看完整版本: 一种有效的包络线算法