%% Use Peak Finder to Find Heart Rate from ECG Input
% This example shows how to use the Time Scope Peak Finder panel to measure
% the heart rate from an ECG.
%%
open_system('ex_timescope_heartbeat')

%%
% To emulate a heart beat, the model Preload creates the variable |mhb| in
% the MATLAB(R) workspace. This variable is then called by the Signal From
% Workspace block. To see all the model Preload commands, open the *Model Explorer* and look at the Callback
% functions.
% 
%%
% Run your model to see the time domain output. 
sim('ex_timescope_heartbeat');
open_system('ex_timescope_heartbeat/Time Scope')
%%
% # To show the *Peak Finder* panel, in the Time Scope menu, select *Tools > Measurements > Peak Finder*. 
% # Expand the Settings section, enter 10 for *Max Num of Peaks*. 
% The Time Scope Peaks section now displays a list of 10 peak amplitude 
% values, and the times at which they occur.
% # Turn on the Cursor Measurements by selecting *Tools > Measurements >
% Cursor Measurements*. 
% # Set the cursor time values to two consecutive peak
% times, for example 1.725 and 2.4. The time difference between all peaks
% is 675 milliseconds. 
%%
% 
% <<../timescope_ecg_measurements.png>>
% 
%%
% Therefore, you can calculate the heart rate of the
% ECG signal: 
%%
% 
% $$\frac{1 \: beat}{675 \: ms} * \frac{60000 \: ms}{1 \: min} = 88.88 \: bpm$$
% 
%%
% Copyright 2018 The MathWorks, Inc.
