There is an example of real-time QRS detection algorithm:
I should say that in biomedical signal processing there are many similar real-time/streaming algorithms, that detect some time events and states, using complicated logic and signal transforms. And my question is about the style and best practice of coding such algorithms, based on this specific Simulink example.
The main algorithm blocks are some common DSP System Objects and a custom Function QRSDetection. QRSDetection is written as frame-based algorithm with sample-based sub-functions that use persistent variables to store its previous states.
On the other hand, System objects "use internal states to store that past behavior, which is used in the next computational step. As a result, System objects are optimized for iterative computations that process large streams of data in segments, such as video and audio processing systems."
1) The first question is, why it was decided to use Matlab Function instead of System object in order to implement the algorithm? And how should it look like if written as a System object?
2) Also, in the algorithm there are many if-else construnctions. Can they be implemented using a Stateflow blocks? And how should it look like?