声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 22180|回复: 31

[共享资源] 一种有效的包络线算法

  [复制链接]
发表于 2006-11-23 16:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本帖最后由 ChaChing 于 2010-9-1 23:43 编辑
  1. function [up,down] = envelope(x,y,interpMethod)

  2. %ENVELOPE gets the data of upper and down envelope of the known input (x,y).
  3. %
  4. %   Input parameters:
  5. %    x               the abscissa of the given data
  6. %    y               the ordinate of the given data
  7. %    interpMethod    the interpolation method
  8. %
  9. %   Output parameters:
  10. %    up      the upper envelope, which has the same length as x.
  11. %    down    the down envelope, which has the same length as x.
  12. %
  13. %   See also DIFF INTERP1

  14. %   Designed by: Lei Wang, <[email]WangLeiBox@hotmail.com[/email]>, 11-Mar-2003.
  15. %   Last Revision: 21-Mar-2003.
  16. %   Dept. Mechanical & Aerospace Engineering, NC State University.
  17. % $Revision: 1.1 $  $Date: 3/21/2003 10:33 AM $

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

  21. if (nargin < 2)|(nargin > 3), error('Please see help for INPUT DATA.');
  22. elseif (nargin == 2),  interpMethod = 'linear'; end
  23.    
  24. % Find the extreme maxim values and the corresponding indexes
  25. %----------------------------------------------------
  26. extrMaxValue = y(find(diff(sign(diff(y)))==-2)+1);
  27. extrMaxIndex =   find(diff(sign(diff(y)))==-2)+1;

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

  32. up = extrMaxValue; up_x = x(extrMaxIndex);
  33. down = extrMinValue; down_x = x(extrMinIndex);

  34. % Interpolation of the upper/down envelope data
  35. %----------------------------------------------------
  36. up = interp1(up_x,up,x,interpMethod);
  37. down = interp1(down_x,down,x,interpMethod);
复制代码

评分

1

查看全部评分

回复
分享到:

使用道具 举报

 楼主| 发表于 2006-11-23 16:27 | 显示全部楼层
本帖最后由 ChaChing 于 2010-9-5 12:09 编辑

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

  5. %   Designed by: Lei Wang, <[email]WangLeiBox@hotmail.com[/email]>, 11-Mar-2003.
  6. %   Last Revision: 21-Mar-2003.
  7. %   Dept. Mechanical & Aerospace Engineering, NC State University.
  8. % $Revision: 1.1 $  $Date: 3/21/2003 10:38 AM $

  9. clc;

  10. % Load a signal waveform
  11. %--------------------------------------------
  12. load data.txt data;
  13. t = data(:,1); % time series
  14. y = data(:,2); % signal data
  15. figure(1); plot(t,y,'b-');  title('The original signal waveform','FontSize',18);

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

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

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

例子所需的数据.txt

22.59 KB, 下载次数: 489

data.txt

发表于 2007-1-9 10:35 | 显示全部楼层
interpMethod 包含几种?
  除了 linear
发表于 2007-1-9 10:50 | 显示全部楼层
“help interp1”, and you will find it

[ 本帖最后由 ChaChing 于 2010-5-3 00:33 编辑 ]
发表于 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
发表于 2008-1-22 22:52 | 显示全部楼层
本帖最后由 ChaChing 于 2010-9-5 12:27 编辑

采用hilbert变换也可以
abs(hilbert(x));就可以
不过问题的重点好像不在这里
发表于 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
1.JPG
发表于 2008-4-25 10:37 | 显示全部楼层

回复 9楼 的帖子

那就先排序,再做嘛。
doc sort
发表于 2008-4-25 15:24 | 显示全部楼层
本帖最后由 ChaChing 于 2010-9-5 12:22 编辑

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

好像用smooth函数也可以达到类似的效果。(5/12)
发表于 2008-7-2 10:44 | 显示全部楼层
首先感谢 Happy教授 !
使用find(diff(sign(diff(y)))==-2)求取极大值的确绝妙
但使用上若有重复点即发生一些小问题如附图
各位大大对如何解决是否有好意见?
zaza.jpg
发表于 2008-12-31 15:00 | 显示全部楼层
你的包络线太精确了,呵呵,有没有一种模糊的啊,画包络线一般就是为了好看,比如区分波包啊之类的,你的有点过头了啊。呵呵
发表于 2010-9-1 10:47 | 显示全部楼层
matlab好像有个自带的啊 效果看上去还要好~~有没有那代码????
发表于 2010-9-1 20:21 | 显示全部楼层
matlab很容易实现,但一般在做包络时先要对信号进行滤波,最近研究LabVIEW声学振动包时才知道的。
发表于 2010-9-5 12:29 | 显示全部楼层
本帖最后由 ChaChing 于 2010-9-5 12:31 编辑

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

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

发表于 2010-11-17 00:16 | 显示全部楼层
这程序如果是曲线上升的,得到的包络线就不对了呀
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-4-27 23:57 , Processed in 0.236682 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表