我有一个窗口大小为300的数据队列。一端添加新数据,另一端删除旧值。
我希望队列数据保持或多或少一致,例如:10,12,15,10,20,然后开始急剧上升:15,10,20,22,25,26,28,30,32 ......一直到150左右。在那里数据可能会有一点波动,然后它会以类似的斜率(120,118,116,115 ......)一直下降到20左右。
我正在尝试以编程方式识别此数据系列中的转折点,但我的代码检测到的峰值比我想要的更频繁。如何确定图表何时上升,何时达到确定的转折点以及何时开始下跌?
NSNumber* last10 = [queue5Min objectAtIndex:[queue5Min count]-10];
NSNumber* last240 = [queue5Min objectAtIndex:[queue5Min count]-240];
int value = 0;
int last240Int = [last240 intValue];//debug
//compare against some point in the past
for(int i = 10; i<20;i++)
{ last10 = [queue5Min objectAtIndex:[queue5Min count]-i];
value += [last10 intValue];
}
value = value/10; //find the average of the point in the past
//attempt to detect sharp rise compared to the past
if( queueValue5Min >25 && queueValue5Min> [last240 intValue]*2)
{
if(queueValue5Min>value)
{
stateMachine5Min = kActivityRising;
NSLog(@">>>>>>>>>>>> 5 min Rising @ %i:, %i, %i",epoch, value,queueValue5Min);
}else if(queueValue5Min <value)
{
NSLog(@">>>>>>>>>>>> 5 min FALLING @ %i:, %i, %i",epoch, value,queueValue5Min);
stateMachine5Min = kActivityFalling;
}
else if(smallActivityCount5Min == value)
{
NSLog(@">>>>>>>>>>>> 5 min peak @ %i:, %i, %i",epoch, value,queueValue5Min);
stateMachine5Min = kSmallActivityAnalyzerActivityPeaked;
}
}else
{
stateMachine5Min = kSmallActivityAnalyzerActivityFlat;
}