electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Needed: Peaks and Troughs Algorithm


Post new topic  Reply to topic    EDAboard.com Forum Index -> Mathematics & Physics -> Needed: Peaks and Troughs Algorithm
Author Message
JimTex



Joined: 05 Aug 2009
Posts: 3
Location: USA


Post06 Aug 2009 3:33   

find peaks


I'm looking for a reliable algroithm for finding and characterizing the Peaks and Troughs in Time series data. My time series is relatively short (500-1000 points) and the primary peaks and troughs are not repeated. Please see the attached Image.

Thanks
Jim



Sorry, but you need login in to view this attachment

Back to top
horzcat



Joined: 24 Jun 2008
Posts: 54
Helped: 2


Post19 Sep 2009 12:30   

find peaks algorithm


if a sample is smaller than it's previous sample and also smaller than the next sample, then that sample is a trough. A similar logic can be formed to find peaks.
Back to top
Google
AdSense
Google Adsense




Post19 Sep 2009 12:30   

Ads




Back to top
AndyECE



Joined: 17 Oct 2008
Posts: 80
Helped: 12


Post04 Nov 2009 1:44   

Needed: Peaks and Troughs Algorithm


You have to lowpass the data first, otherwise you will get too many false troughs

Here's an example script I threw together:

Added after 8 seconds:

%Create a signal that looks kinda like yours
t = 1:1000;
noise = randn(1,length(signal));
signal = 10*sin(.02*t) + 4*sin(.05*t)+noise;

%Output vector
output = zeros(1,length(signal));

%Lowpass the signal to get rid of high-frequency content. Note that
%filtfilt will avoid biasing the signal. The exact values of the filter
%were tweaked until they looked right
[b a]=butter(4,.05);
lowpass_signal = (filtfilt(b, a, signal));

plot(t, signal, t, lowpass_signal);
title('Comparison of signals');
legend('Original', 'Filtered');

%Find the rate of change of the filtered signal
slope = diff(lowpass_signal);

%Trough:
% Zero slope, less than surrounding values
% Plug a -1 into the output vector at that spot
%Peak:
% Zero slope, greater than surrounding values
% Plug a -1 into the output vector at that spot

for i = 1:(length(signal)-6)
if (abs(slope(i))<.005 && lowpass_signal(i-5)<lowpass_signal(i) && lowpass_signal(i+5)<lowpass_signal(i))
output(i)=1;
elseif (abs(slope(i))<.005 && lowpass_signal(i-1)>lowpass_signal(i) && lowpass_signal(i+5)>lowpass_signal(i))
output(i)=-1;
end
end

disp('Troughs are located at index: ');
find(output==-1)

disp('Peaks are located at index: ');
find(output==1)
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Mathematics & Physics -> Needed: Peaks and Troughs Algorithm
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
peaks detection (6)
Viterbi algorithm and BCJR algorithm (3)
wideband coupler: Peaks in the response (6)
Circuit to detect time between two voltage peaks. HELP (5)
C Algorithm Help Needed (58)
explanation of sorting algorithm needed (3)
DES algorithm code needed (1)
DES algorithm code needed (2)
an algorithm on how to demodulate a CDMA or WCDMA needed (2)
About Rosenfelds Thinning Algorithm - Documentation needed (1)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS