使用Matlab在时间序列中查找局部峰谷 [英] Finding Local peaks and troughs in a Time Series using Matlab

查看:196
本文介绍了使用Matlab在时间序列中查找局部峰谷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来计算各种资产的时间序列数据中的峰值.峰值定义为时间序列中大于其相邻点的任何点.根据峰的数量,我在代码中计算出一个分数,如下所示. input_args采用这种格式,rc是input_args的大小.这段代码可以正常工作,但是当我在很长一段时间内跨资产调用它时,会花费很多时间.是他们使此代码更高效的一种方法.我正在寻找一种解决方案,通过该解决方案,我可以制作一个逻辑数组来识别时间序列中满足峰值条件的点,然后将其隔离以计算分数?

I am using the following code to calculate peaks in a time series data across various assets. Peak is defined as any point in time series which is greater than its neighboring points. Based on the number of peaks I calculate a score in the code as shown below. The input_args is in this format and rc is size of input_args. This code works fine but takes a lot of time when I call it across assets for long time series. Is their a way to make this code more efficient. I am looking for a solution through which I can make a logical array to identify the points in time series which satisfy the condition of being a peak and then isolate them to calculate the score ?

Data:-
1
0.997
0.979
0.952
0.935
0.942
0.987
1.027
1.036
1.049

function [maxhill] = hill_calc(input_args,rc)
for i=2:rc(1)-1    
    if and(input_args(i)>input_args(i+1),input_args(i)>input_args(i-1))
    output_args_hills(i-1) = 2*input_args(i)-input_args(i+1)-input_args(i-1);
    else output_args_hills(i-1) = NaN;
    end
end
maxhill = max(output_args_hills);   
end

推荐答案

您可以轻松地计算出峰的指数,如下所示:

You can compute the indices of the peaks easily as follows:

ind = 1+find((input_args(2:end-1)>input_args(1:end-2)) & ...
    (input_args(2:end-1)>input_args(3:end)));

示例_

>> input_args = [1 2 5 4 7];

给予

ind =
     3

表示只有第三个值是峰值.

meaning that only the third value is a peak.

这篇关于使用Matlab在时间序列中查找局部峰谷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆