zoukankan      html  css  js  c++  java
  • 统计波形图波峰波谷大于某个幅度的数目

    - (void)updateWithYValue:(CGFloat)newY {
        
        if (!isnan(newY)) {
    
            if (!_shouldResetConfiguration) {
                _minValue = newY;
                _maxValue = newY;
                _startValue = NO;
                _didCheckerFindingTarget = NO;
                _shouldResetConfiguration = YES;
            } else {
                if (!_didCheckerFindingTarget) {
                    _maxValue = MAX(_maxValue, newY);
                    _minValue = MIN(_minValue, newY);
                    CGFloat gapFromMaxValue = (ABS(_maxValue - newY));
                    CGFloat gapFromMinValue = (ABS(newY - _minValue));
                    if (gapFromMaxValue >= self.minDistanceChangeForAllowRecordNumber) {
                        _didCheckerFindingTarget = YES;
                        _findingTopValue = NO;
                        _criticalValue = newY;
                        _maxValue = newY;
                        _foundTargetCount = 1;
                    } else if (gapFromMinValue >= self.minDistanceChangeForAllowRecordNumber) {
                        _didCheckerFindingTarget = YES;
                        _findingTopValue = YES;
                        _criticalValue = newY;
                        _minValue = newY;
                        _foundTargetCount = 1;
                    }
                } else {
                    if (_findingTopValue) {
                        if (newY >= _criticalValue) {
                            _maxValue = MAX(newY, _maxValue);
                            _minValue = newY;
                            CGFloat gapFromMaxValue = (ABS(_maxValue - newY));
                            if (gapFromMaxValue >= self.minDistanceChangeForAllowRecordNumber) {
                                _criticalValue = newY;
                                _findingTopValue = NO;
                                if (_foundTargetCount % 2 == 0) {
                                    [self addOneChangeCount];
                                }
                            }
                        } else {
                            CGFloat gapFromMaxValue = (ABS(_maxValue - newY));
                            _minValue  = MIN(_minValue, newY);
                            CGFloat gapFromMinValue = (ABS(newY - _minValue));
                            if (gapFromMaxValue >= self.minDistanceChangeForAllowRecordNumber) {
                                _foundTargetCount += 1;
                                _criticalValue = newY;
                                _minValue = newY;
                                _findingTopValue = NO;
                                if (_foundTargetCount % 2 == 0) {
                                    [self addOneChangeCount];
                                    printf("==============>2
    ");
                                }
                            } else if (gapFromMinValue >= self.minDistanceChangeForAllowRecordNumber) {
                                ///异常,需要忽略一半波形
                                _criticalValue = newY;
                                _maxValue = newY;
                                _findingTopValue = YES;
                            }
                        }
                    } else {
                        if (newY <= _criticalValue) {
                            _minValue = MIN(newY, _minValue);
                            _maxValue = newY;
                            CGFloat gapFromMinValue = (ABS(newY - _minValue));
                            if (gapFromMinValue >= self.minDistanceChangeForAllowRecordNumber) {
                                _foundTargetCount += 1;
                                _criticalValue = newY;
                                _findingTopValue = YES;
                                if (_foundTargetCount % 2 == 0) {
                                    [self addOneChangeCount];
                                }
                            }
                        } else {
                            CGFloat gapFromMinValue = (ABS(newY - _minValue));
                            _maxValue  = MAX(_maxValue, newY);
                            CGFloat gapFromMaxValue = (ABS(_maxValue - newY));
                            if (gapFromMinValue >= self.minDistanceChangeForAllowRecordNumber) {
                                _foundTargetCount += 1;
                                _criticalValue = newY;
                                _maxValue = newY;
                                _findingTopValue = YES;
                                if (_foundTargetCount % 2 == 0) {
                                    [self addOneChangeCount];
                                }
                            } else if (gapFromMaxValue >= self.minDistanceChangeForAllowRecordNumber) {
                                ///异常,需要忽略一半波形
                                _criticalValue = newY;
                                _minValue = newY;
                                _findingTopValue = NO;
                            }
                        }
                    }
                }
            }
        }
    }

    假设第一个点为最低值,根据下一个点判断趋势,记录探测接下来的值,记录max和min,当当前点达到触发临界差值,认定触发了一个波峰/波谷。若为波峰,保留最高值,探测下面的值,当探测到最高点到当前点差值到达临界值认为下到一个波谷,计数加1。

  • 相关阅读:
    hdu 1022 Train Problem I 模拟
    Eclipse plugin开发 —实现语法高亮
    一篇英文版的eclipse插件textEditor资料
    (转)Eclipse常用快捷键
    Eclipse plugin开发 —实现单行与多行注释
    Eclipse plugin开发 —实现文本内容帮助
    CSS borderstyle
    ClassLoader getResource
    javascript add table content from xml
    postgres 当前时间
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/13879967.html
Copyright © 2011-2022 走看看