Main Content

Real-Time ECG QRS Detection on ARM Cortex-M Processor

This example shows how to generate and run optimized code for real-time QRS detection of an electrocardiogram (ECG) signal on the ARM® Cortex®-M processor. It uses an ECG signal selector for choosing ECG signal sources with different mean heart rates in the Simulink® environment. The optimized code uses the CMSIS library for the discrete FIR blocks in the example.

Introduction

The electrocardiogram (ECG) is a recording of body surface potentials generated by the electrical activity of the heart. Clinicians can evaluate an individual's cardiac condition and overall health from the ECG recording and perform further diagnosis. Because of the physiological variability of the QRS complex and various types of noise present in the real ECG signal, it is challenging to accurately detect the QRS complex. The real-time QRS detection algorithm is described in the Real-Time ECG QRS Detection example of DSP System Toolbox.

The CMSIS library contains a set of optimized signal processing algorithms for ARM Cortex-M processors. This example shows how to optimize the generated code of a ECG QRS detection model with code replacement from the CMSIS library for ARM Cortex-M processors.

Required Hardware

  • STMicroelectronics STM32F4-Discovery Board

Open the ex_ecg_sigprocessing_cmsis

Task 1: Simulate

1. Open the ex_ecg_sigprocessing_cmsis model.

2. Change your current folder in MATLAB® to a writable folder.

3. On the model tool strip, click Run to start the simulation.

4. Use the ECG Signal Selector to switch among ECG signals with different mean heart rates.

5. Click Stop to end simulation.

Task 2: Configure model for Code Replacement and PIL Simulation

1. Under Simulation, click Model Configuration Parameters to open the dialog box.

2. Select the Code Generation category.

3. Set System target file to ert.tlc. Select Target hardware as STM32F4-Discovery. Set Toolchain to GNU Tools for ARM Embedded Processors.

4. Select Interface under the Code Generation category. Set Code replacement library to ARM Cortex-M.

5. Select Verification under the Code Generation category. In SIL or PIL verification block panel, set Create block to PIL.

6. Select Coder Target category. Set the PIL communication interface as Serial (USART2); COM port based on your computer's COM port number.

Task 3: Create a PIL block with Optimized Code on ARM Cortex-M Processor

1. Create a PIL block for the ECGSignalProcessingSubsystem block by following Task 1 in example Code Verification and Validation with PIL and External Mode of Embedded Coder Support Package for STMicroelectronics Discovery Boards.

2. When the build finishes, examine the generated code of the PIL block by clicking on the ECGSignalProcessingSubsystem.c file. Notice the multiple function calls, arm_fir_f32, in the generated C code.

Task 4: Real-Time Processing with Processor-in-Loop Mode

1. Replace the ECGSignalProcessingSubsystem block with the generated processor-in-loop (PIL) block.

2. On the model tool strip, click Run to start the simulation with PIL block. The PIL block runs on the STM32F4-Discovery board. All other parts of the model run on the host machine. The STM32F4-Discovery board communicates with the host via PIL block input and output.

3. Use the drop down menu of the ECG Signal Selector to switch among ECG signals with different mean heart rates.

4. To configure, build, and run the model in external mode, follow the steps in the Code Verification and Validation with PIL and External Mode example of Embedded Coder Support Package for STMicroelectronics Discovery Boards.