Real-time peak detection in noisy sinusoidal time-series

前端 未结 2 2029
故里飘歌
故里飘歌 2021-01-31 13:06

I have been attempting to detect peaks in sinusoidal time-series data in real time, however I\'ve had no success thus far. I cannot seem to find a real-time alg

2条回答
  •  一生所求
    2021-01-31 13:15

    Consider using findpeaks, it is fast, which may be important for realtime. You should filter high-frequency noise to improve accuracy. here I smooth the data with a moving window.

    t = 0:0.001:10;
    x = 0.3*sin(t) + sin(1.3*t) + 0.9*sin(4.2*t) + 0.02*randn(1, 10001);
    [~,iPeak0] = findpeaks(movmean(x,100),'MinPeakProminence',0.5);
    

    You can time the process (0.0015sec)

    f0 = @() findpeaks(movmean(x,100),'MinPeakProminence',0.5)
    disp(timeit(f0,2))
    

    To compare, processing the slope is only a bit faster (0.00013sec), but findpeaks have many useful options, such as minimum interval between peaks etc.

    iPeaks1 = derivePeaks(x);
    f1 = @() derivePeaks(x)
    disp(timeit(f1,1))
    

    Where derivePeaks is:

    function iPeak1 = derivePeaks(x)
    xSmooth = movmean(x,100);
    goingUp = find(diff(movmean(xSmooth,100)) > 0);
    iPeak1 = unique(goingUp([1,find(diff(goingUp) > 100),end]));
    iPeak1(iPeak1 == 1 | iPeak1 == length(iPeak1)) = [];
    end
    

提交回复
热议问题