Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

MATLAB Program to detect top and bottom of a graph with code


Code:

%function find_peaks()

flow_data = load('flow.csv');

 

time = flow_data(:,1);

blood_flow = flow_data(:,2);

smooth_blood_flow = smooth(blood_flow);

 

%Warning message, Provided list does not contain data

if isempty(smooth_blood_flow)

    warning('find_trough: %smooth_blood_flow','empty list');

end

 

%Plot: Smoothed out data

plot(time, smooth_blood_flow,'b')

title({'Smoothed Flow'}, 'FontAngle','italic')

xlabel({'Time (ms)'})

ylabel({'Flow'})

hold on

 

%Peaks and Troughs

s = smooth_blood_flow;

troughs = [];

peaks = [];

 

%%Peaks (Treshold = 300)

for i= 3: length(smooth_blood_flow)-2

    if (s(i)>300) && (s(i-1) < s(i)) && (s(i-2) < s(i-1)) && ...

       (s(i) > s(i+1)) && (s(i+1) > s(i+2))

        peaks(end+1) = i;

    end

    plot(time(peaks), smooth_blood_flow(peaks), 'r*')

    hold on

end

s1=s(1:end-2);

s2=s(2:end-1);

s3=s(3:end);

% minimums:

op=1+find((s1>=s2)&(s2<=s3));

figure(2);

plot(time, smooth_blood_flow,'b');

title({'Smoothed Flow'}, 'FontAngle','italic')

xlabel({'Time (ms)'})

ylabel({'Flow'})

hold on

for i= 1: length(op)

    plot(time(op(i)), smooth_blood_flow(op(i)), 'r*')

    hold on

end

 



Join us on Telegram: https://t.me/matlabcastor

No comments

Popular Posts