MATLAB: How to use the QRS Detection code from Simulink in MATLAB

cardiogramdigitalDSP System Toolboxecgecoprocessingsignal

I am following the Simulink example:
<https://www.mathworks.com/help/dsp/examples/real-time-ecg-qrs-detection.html https://www.mathworks.com/help/dsp/examples/real-time-ecg-qrs-detection.html >
I noticed that there is a MATLAB Fcn Block that has QRS Detection code. Is it possible to use this code in MATLAB, without having to create a Simulink model? If so, how do I achieve that?

Best Answer

This is certainly possible to do and all you need to do is copy-paste the code into a separate M file and use it like any other MATLAB function.
The more involved part will be processing the input argument "u" in a similar fashion to the one used in the example. The Simulink example's heart rate signal is filtered several times like so:
Raw heart rate signal
Buffer to 90 samples
Resample to 200Hz
Bandpass Filter
Differentiator Filter
Absolute Value
Discrete FIR Filter (moving average)
Then input to QRS Detection.
All the above Blocks have equivalent code or DSP System Toolbox functions that can be used in MATLAB scripts. For example. the Bandpass Filter Block has an equivalent function:
You can find alternatives in MATLAB code to all these Simulink Blocks and construct the example in MATLAB scripts.
Related Question