基于matlab的简单的寻找波峰波谷处理方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_23338865/article/details/53787330
clc; close all; clear;
% 节点信息
data=[105.03 99.18 84.965 72.445 68.994 77.265...
    91.052 100.61 98.215 86.363 74.439 71.625...
    80.061 92.18 97.823 91.483 80.241 73.616...
    78.547 89.084 94.924 89.689 79.898 75.485...
    81.544 89.485 90.578 83.712 77.401 80.18...
    86.904 88.721 83.468 78.971 81.983 86.25...
    85.224 80.901 80.808 84.488];
% 微分变号信息
c=findpeaks(data);
IndMin=find(diff(sign(diff(data)))>0)+1;   %获得局部最小值的位置
IndMax=find(diff(sign(diff(data)))<0)+1;   %获得局部最大值的位置
figure; hold on; box on;
plot(1:length(data),data);
plot(IndMin,data(IndMin),'r^')
plot(IndMax,data(IndMax),'k*')
legend('曲线','波谷点','波峰点')
title('计算离散节点的波峰波谷信息', 'FontWeight', 'Bold');


初始化一段数据,寻找波峰波谷数据如下:




求极值的具体语句:

        极值:
        data是你的数据,
        find(diff(sign(diff(data)))==-2)+1
        找到极大值的位置

        find(diff(sign(diff(data)))==2)+1
        找到极小值的位置

        data(find(diff(sign(diff(data)))==-2)+1)和
        data(find(diff(sign(diff(data)))==2)+1)
        返回的是极大值和极小值

要想diff(sign(diff))出现-2,只有是sign的结果为-1,1排列的时候,-1代表,前一次的diff运算前面的数值比后面大,1代表,后一次diff运算后面的数值比前面大,因而,x-a,x,x+b,a,b均为正数,则x为极小值。

同理判断极大值。

find查找到极值的索引后还要+1,是因为,差分运算(diff)后的数据的长度比原始数据少1,见help。



%方法一
x=0:0.01:20;
y=2*sin(x/2)+cos(2*x)/2;
% indmax=find(diff(sign(diff(y)))<0)+1;%极大值点
% indmin=find(diff(sign(diff(y)))>0)+1;%极小值点
ind=find(diff(sign(diff(y)))~=0)+1;%极值点
plot(x,y,x(ind),y(ind),'ro')



%方法二
x=0:0.01:20;
y=2*sin(x/2)+cos(2*x)/2;
indmax=intersect(find(diff(y)>0)+1,find(diff(y)<0));%极大值点
indmin=intersect(find(diff(y)<0)+1,find(diff(y)>0));%极小值点
plot(x,y,x(indmax),y(indmax),'ro',x(indmin),y(indmin),'go')



%方法三
x=0:0.01:20;
y=2*sin(x/2)+cos(2*x)/2;
yf=y(2:end-1)-y(1:end-2); %前向差分
yb=y(2:end-1)-y(3:end);   %后向差分
I=find(yf.*yb>=0)+1;      %寻找极值点(不考虑首尾两点)
plot(x,y,'b',x(I),y(I),'r*');


波峰波谷

06-24

[img=http://img.bbs.csdn.net/upload/201306/24/1372071142_126818.jpg][/img]rnrn问题描述:rn对于任意给出的一组随机数列,求出离给出点和指定区间(即给出点往前多少个单位)最近的上波浪或下波浪,结果表示为两个点的坐标。rn如给出的点在B与C之间,给出的指定区间为30,则答案为(3,5.15)和(24,3.3),即A、B两个点的坐标。rn给出的点在E、F之间,给定的区间为30,则答案为(54,3.3)和(62,4.55),即D、E两点的坐标rnrn大家能帮忙想一下吗?rnrn数据:rn(1,4.6)(2,4.7)(3,5.15)(4,5.05)(5,5.1)(6,4.8)(7,4.7)(8,4.65)(9,4.7)(10,4.4)(11,4.0)(12,3.85)(13,3.65)(14,3.7)(15,3.85)(16,4.05)(17,3.8)(18,3.95)(19,4.0)(20,3.9)(21,3.65)(22,3.85)(23,3.5)(24,3.3)(25,3.3)(26,3.35)(27,3.35)(28,3.55)(29,3.45)(30,3.75)(31,4.15)(32,4.0)(33,4.05)(34,4.25)(35,4.1)(36,3.85)(37,3.95)(38,4.15)(39,4.0)(40,4.0)(41,3.75)(42,3.35)(43,3.25)(44,3.9)(45,4.0)(46,4.0)(47,4.05)(48,3.85)(49,3.85)(50,3.45)(51,3.4)(52,3.45)(53,3.4)(54,3.3)(55,3.7)(56,4.0)(57,4.15)(58,3.95)(59,4.2)(60,4.3)(61,4.45)(62,4.55)(63,4.5)(64,3.95)(65,3.8)(66,3.75)(67,3.7)(68,3.75)(69,3.75)(70,3.8)(71,3.75)(72,3.7)(73,3.75)(74,3.6)(75,3.2)(76,3.25)(77,3.2)(78,3.05)(79,2.8)(80,2.9)(81,2.75)(82,2.85)(83,2.85)(84,2.85)(85,2.85)(86,3.15)(87,3.6)(88,3.9)(89,3.95)(90,4.05)(91,3.75)(92,3.75)(93,4.15)(94,4.15)(95,4.35)(96,4.1)(97,4.0)(98,4.1)(99,4.4)(100,4.25)(101,4.35)(102,4.15)(103,4.15)(104,4.1)(105,4.2)(106,4.0)(107,3.9)(108,3.65)(109,3.85)(110,3.7)(111,3.75)(112,3.8)(113,3.35)(114,3.55)(115,3.35)(116,3.3)(117,3.5)(118,3.6)(119,3.35)(120,3.3)(121,3.55)(122,3.75)(123,3.75)(124,4.0)(125,4.0)(126,3.95)(127,3.7)(128,3.6)(129,3.4)(130,3.65)(131,3.6)(132,3.55)(133,3.6)(134,3.3)(135,3.55)(136,3.55)(137,3.2)(138,3.1)(139,3.1)(140,3.2)(141,3.35)(142,3.2)(143,3.45)(144,3.2)(145,3.15)(146,3.25)(147,3.2)(148,3.5)(149,3.5)(150,3.4)(151,3.5)(152,4.1)(153,4.3)(154,4.35)(155,4.1)(156,4.0)(157,4.0)(158,4.15)(159,4.2)(160,4.2)(161,3.75)(162,3.8)(163,3.55)(164,3.7)(165,3.75)(166,3.6)(167,3.55)(168,3.35)(169,3.35)(170,3.3)(171,3.3)(172,2.7)(173,2.6)(174,2.6)(175,2.85)(176,3.05)(177,3.35)(178,3.1)(179,3.0)(180,3.05)(181,3.55)(182,3.7)(183,3.7)(184,4.2)(185,4.1)(186,4.2)(187,4.2)(188,4.1)(189,4.3)(190,4.25)(191,4.35)(192,4.45)(193,4.6)(194,4.6)(195,4.35)(196,4.4)(197,4.45)(198,4.45)(199,4.7)(200,4.75)(201,4.8)(202,4.6)(203,4.65)(204,4.05)(205,4.1)(206,4.05)(207,4.25)(208,4.3)(209,4.45)(210,4.55)(211,4.5)(212,4.65)(213,4.3)(214,4.75)(215,4.9)(216,4.6)(217,4.25)(218,4.5)(219,4.25)(220,4.35)(221,3.9)(222,4.15)(223,4.45)(224,4.5)(225,4.45)(226,4.35)(227,4.4)(228,4.35)(229,4.0)(230,3.9)(231,3.75)(232,3.7)(233,3.75)(234,3.45)(235,3.5)(236,3.5)(237,4.2)(238,4.0)(239,4.1)(240,3.85)(241,3.7)(242,3.4)(243,3.15)(244,3.1)(245,3.1)(246,3.4)(247,3.6)(248,3.7)(249,3.8)(250,3.85)(251,3.85)(252,3.7)(253,3.7)(254,3.65)(255,3.75)(256,4.0)(257,3.45)(258,3.55)(259,3.8)(260,3.95)(261,3.95)(262,4.0)(263,4.15)(264,4.2)(265,4.25)(266,3.95)(267,3.6)(268,3.5)(269,3.55)(270,3.45)(271,3.65)(272,3.9)(273,3.9)(274,4.2)(275,3.95)(1,4.6)(2,4.7)(3,5.15)(4,5.05)(5,5.1)(6,4.8)(7,4.7)(8,4.65)(9,4.7)(10,4.4)(11,4.0)(12,3.85)(13,3.65)(14,3.7)(15,3.85)(16,4.05)(17,3.8)(18,3.95)(19,4.0)(20,3.9)(21,3.65)(22,3.85)(23,3.5)(24,3.3)(25,3.3)(26,3.35)(27,3.35)(28,3.55)(29,3.45)(30,3.75)(31,4.15)(32,4.0)(33,4.05)(34,4.25)(35,4.1)(36,3.85)(37,3.95)(38,4.15)(39,4.0)(40,4.0)(41,3.75)(42,3.35)(43,3.25)(44,3.9)(45,4.0)(46,4.0)(47,4.05)(48,3.85)(49,3.85)(50,3.45)(51,3.4)(52,3.45)(53,3.4)(54,3.3)(55,3.7)(56,4.0)(57,4.15)(58,3.95)(59,4.2)(60,4.3)(61,4.45)(62,4.55)(63,4.5)(64,3.95)(65,3.8)(66,3.75)(67,3.7)(68,3.75)(69,3.75)(70,3.8)(71,3.75)(72,3.7)(73,3.75)(74,3.6)(75,3.2)(76,3.25)(77,3.2)(78,3.05)(79,2.8)(80,2.9)(81,2.75)(82,2.85)(83,2.85)(84,2.85)(85,2.85)(86,3.15)(87,3.6)(88,3.9)(89,3.95)(90,4.05)(91,3.75)(92,3.75)(93,4.15)(94,4.15)(95,4.35)(96,4.1)(97,4.0)(98,4.1)(99,4.4)(100,4.25)(101,4.35)(102,4.15)(103,4.15)(104,4.1)(105,4.2)(106,4.0)(107,3.9)(108,3.65)(109,3.85)(110,3.7)(111,3.75)(112,3.8)(113,3.35)(114,3.55)(115,3.35)(116,3.3)(117,3.5)(118,3.6)(119,3.35)(120,3.3)(121,3.55)(122,3.75)(123,3.75)(124,4.0)(125,4.0)(126,3.95)(127,3.7)(128,3.6)(129,3.4)(130,3.65)(131,3.6)(132,3.55)(133,3.6)(134,3.3)(135,3.55)(136,3.55)(137,3.2)(138,3.1)(139,3.1)(140,3.2)(141,3.35)(142,3.2)(143,3.45)(144,3.2)(145,3.15)(146,3.25)(147,3.2)(148,3.5)(149,3.5)(150,3.4)(151,3.5)(152,4.1)(153,4.3)(154,4.35)(155,4.1)(156,4.0)(157,4.0)(158,4.15)(159,4.2)(160,4.2)(161,3.75)(162,3.8)(163,3.55)(164,3.7)(165,3.75)(166,3.6)(167,3.55)(168,3.35)(169,3.35)(170,3.3)(171,3.3)(172,2.7)(173,2.6)(174,2.6)(175,2.85)(176,3.05)(177,3.35)(178,3.1)(179,3.0)(180,3.05)(181,3.55)(182,3.7)(183,3.7)(184,4.2)(185,4.1)(186,4.2)(187,4.2)(188,4.1)(189,4.3)(190,4.25)(191,4.35)(192,4.45)(193,4.6)(194,4.6)(195,4.35)(196,4.4)(197,4.45)(198,4.45)(199,4.7)(200,4.75)(201,4.8)(202,4.6)(203,4.65)(204,4.05)(205,4.1)(206,4.05)(207,4.25)(208,4.3)(209,4.45)(210,4.55)(211,4.5)(212,4.65)(213,4.3)(214,4.75)(215,4.9)(216,4.6)(217,4.25)(218,4.5)(219,4.25)(220,4.35)(221,3.9)(222,4.15)(223,4.45)(224,4.5)(225,4.45)(226,4.35)(227,4.4)(228,4.35)(229,4.0)(230,3.9)(231,3.75)(232,3.7)(233,3.75)(234,3.45)(235,3.5)(236,3.5)(237,4.2)(238,4.0)(239,4.1)(240,3.85)(241,3.7)(242,3.4)(243,3.15)(244,3.1)(245,3.1)(246,3.4)(247,3.6)(248,3.7)(249,3.8)(250,3.85)(251,3.85)(252,3.7)(253,3.7)(254,3.65)(255,3.75)(256,4.0)(257,3.45)(258,3.55)(259,3.8)(260,3.95)(261,3.95)(262,4.0)(263,4.15)(264,4.2)(265,4.25)(266,3.95)(267,3.6)(268,3.5)(269,3.55)(270,3.45)(271,3.65)(272,3.9)(273,3.9)(274,4.2)(275,3.95)

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试