%% c_FindPeaksDemo.m
% ME370 Data Peak Finding
clear all; close all; clc

%% Load Data & Plot
load('ForcePlateData')

figure(1)
plot(t,dataN_L)
title('Scaled vGRF Data, Left')
xlabel('Time [s]')
ylabel('[N]')

%% Using findpeaks
figure(2);
%TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
% TASK: Identify peak heights and locations using the findpeaks
% function with the arguments dataN_L and rate
[L_pks, L_loc] =  % note the inputs are different than the line below
findpeaks(dataN_L,rate); % plots the result
title('Basic findpeaks Result')
xlabel('Time [s]')
ylabel('[N]')

%% Use Name-Value pairs to find one peak per gait cycle
figure(3);
stepPeriod = 1; % s, approximate, from plot inspection 
peakDist = stepPeriod/2;
%TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
% TASK: Modify the findpeaks input list with the name-value pair
% 'MinPeakDistance',peakDist
[L_pks, L_loc] = findpeaks(dataN_L, rate, );
findpeaks(dataN_L, rate, 'MinPeakDistance',peakDist);
title('findpeaks Minimum Peak Distance')
xlabel('Time [s]')
ylabel('[N]')

%% Use Name-Value pairs to find BOTH peaks per gait cycle
figure(4);
peakRelativeHeight = 300; % N, height above neighboring valley  
%TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
% TASK: Modify the findpeaks input list with the name-value pair
% 'MinPeakProminence',peakRelativeHeight
[L_pks, L_loc] = findpeaks(dataN_L, rate, );
findpeaks(dataN_L, rate, 'MinPeakProminence',peakRelativeHeight);
title('findpeaks Minimum Prominence')
xlabel('Time [s]')
ylabel('[N]')

%% This can be repeated for the right side