Live Workshop Materials

ECG Signal Processing Workshop with Python

A Practical Introduction to Biomedical Signal Processing in Python

Dr Mahdi Torabi — Torabi Signals Ltd.

About This Workshop

This workshop takes you step by step through the fundamentals of ECG (Electrocardiogram) signal processing using Python . No prior signal processing experience is needed. Each section builds on the previous one, and every step has clear tasks for you to try.

Signal Specifications

  • Signal: Synthetic single-channel ECG
  • Sampling rate: 256 Hz
  • Duration: 256 seconds (~4.3 minutes)
  • Samples: 65,536
  • Amplitude range: −0.4 to 1.2 mV
  • MATLAB option: ECG_Workshop.m for students following the MATLAB track.
  • Python option: Use the Python workshop files if you prefer coding in Python.

Download Workshop Files

Download the workshop files you want to share before starting the workshop.

ECG Workshop Guide

Complete written guide with explanations, diagrams, and glossary.

.docx Download

ECG Workshop Script

MATLAB starter script for students working through the workshop step by step.

.m Download

ECG Signal Data

65,536-sample ECG recording at 256 Hz.

.mat Download

Python Files for Python Workshop

Python materials for students who want to follow the workshop in Jupyter or another Python environment.

Python Download

How Students Can Get Started

Follow these steps to start the workshop in MATLAB or Python. No advanced programming background is required.

Prerequisites

  • Choose one path: MATLAB or Python
  • MATLAB path: MATLAB R2020a or newer, plus Signal Processing Toolbox and Communications Toolbox
  • Python path: Python 3.10+ with a notebook or code editor such as Jupyter Notebook, VS Code, or Spyder
  • Common Python packages such as NumPy, SciPy, Matplotlib, and Pandas if your Python materials use them
  • Approximately 50 MB free disk space

Tip: Many students can access MATLAB free through their university, while Python can usually be installed free on personal computers.

1

Download the files for your track

Download the workshop guide, ECG data, and the coding files for the track you want to follow from the download section above.

2

Create a workshop folder

Create a new folder on your computer and place the downloaded workshop files into it so your guide, data, and code stay together:

  • Windows: C:\Users\YourName\Documents\ECG_Workshop\
  • Mac: ~/Documents/ECG_Workshop/
3

Open your coding environment

Open MATLAB or your Python environment, then navigate to the folder you just created. You should see your workshop files listed there.

Important: Keep the ECG data file in the same working folder as your script or notebook. If your code cannot find the data file, you are probably in the wrong folder.
4

Open the MATLAB or Python file

Open the MATLAB script if you are following the MATLAB track, or open the Python file or notebook if you are following the Python track.

5

Run the workshop in small steps

Work through the file section by section so you can understand what each step is doing before moving on.

  • MATLAB: Click inside any section and press Ctrl+Enter (Windows) or Cmd+Enter (Mac)
  • Python: Run one notebook cell or code block at a time in your chosen editor
Do not run everything at once. The workshop is designed to help students learn one step at a time.
6

Follow the student tasks

Read the prompts, TODO comments, or notebook notes before running each part. They tell students what to observe, what to change, and what to compare.

Troubleshooting Common Issues

“My code cannot find the ECG data file”

Your code editor is probably not in the correct folder. Open the folder where you saved the workshop files and make sure the ECG data file is in the same working directory as your MATLAB or Python file.

“MATLAB says a function is undefined”

You may be missing a required toolbox. In MATLAB, go to Home > Add-Ons > Get Add-Ons and install the toolbox named in the error message, such as Communications Toolbox or Signal Processing Toolbox.

“Python says a package is missing”

Install the missing package in your Python environment before continuing. Common workshop packages may include numpy, scipy, matplotlib, and pandas.

“I ran everything and got too many plots or outputs at once”

Run the workshop one section, cell, or block at a time. This makes it easier for students to understand the signal-processing steps and compare the outputs.

“The figures are too small / overlapping”

You can resize MATLAB figure windows by dragging their edges. You can also dock them into the MATLAB desktop by clicking the small arrow icon.

“I don’t have MATLAB — can I still follow along?”

Yes. If you have the Python workshop files, you can follow the Python track instead. If you still want to use MATLAB, you can also try MATLAB Online at matlab.mathworks.com.

Workshop Sections Overview

Students move through 6 progressive signal-processing steps in MATLAB or Python.

1

Load ECG Data

Load the ECG dataset, set the sampling rate to 256 Hz, and inspect the basic signal properties.

Key concept: Sampling frequency determines what frequencies you can detect.

2

Plot the Full ECG

Display the entire 256-second recording. Observe the repeating heartbeat pattern.

Key concept: Visual inspection is always the first step in signal processing.

3

Zoom Into 5 Seconds

Zoom into a short window to see individual P, QRS, and T waves clearly.

Key concept: Count R-peaks in 5 seconds × 12 = heart rate in BPM.

4

Add Noise

Corrupt the signal with white Gaussian noise and 50 Hz powerline interference.

Key concept: SNR (Signal-to-Noise Ratio) — higher dB = less noise.

5

Filter the Noise

Apply a Bandpass filter (0.5–40 Hz) and a Notch filter (50 Hz) to clean the signal.

Key concept: Different noise types need different filter strategies.

6

FFT Frequency Analysis

Use the Fast Fourier Transform to see which frequencies are present in the signal.

Key concept: FFT reveals noise that is invisible in the time domain.

Key Parameters Reference

Students can experiment with these values to see how they affect the signal.

Parameter Default Location What It Controls
start_sec 10 Section 3 Start time of the 5-second zoom window
snr_wgn 20 dB Section 4 White Gaussian Noise strength (lower = noisier)
powerline_amp 0.3 mV Section 4 50 Hz powerline sine wave amplitude
bp_low 0.5 Hz Section 5 Bandpass filter lower cutoff
bp_high 40 Hz Section 5 Bandpass filter upper cutoff
notch_bw 2 Hz Section 5 Width of the 50 Hz notch filter

Glossary

ECG / EKG
Electrocardiogram: a recording of the heart’s electrical activity.
PQRST complex
The characteristic shape of one heartbeat.
R-peak
The tallest spike in the QRS complex, used to detect each beat.
Sampling frequency (fs)
Samples recorded per second (256 Hz in this workshop).
SNR
Signal-to-Noise Ratio in dB; higher = cleaner signal.
White Gaussian Noise
Random noise spread across all frequencies.
Powerline interference
50/60 Hz noise from mains electricity.
Bandpass filter
Keeps a frequency range, removes everything outside it.
Notch filter
Removes one narrow frequency band (e.g. exactly 50 Hz).
FFT
Fast Fourier Transform: converts signal from time to frequency domain.
BPM
Beats Per Minute: heart rate = heartbeat frequency × 60.
Nyquist frequency
Maximum detectable frequency = fs ÷ 2.

Disclaimer

This workshop uses synthetic ECG data for educational purposes only. The signal and analysis results are NOT from a real patient and must NOT be used for any clinical or diagnostic purpose. For medical concerns, always consult a qualified healthcare professional.

Contact

  • Website: torabisignals.com
  • Email: mahdi@torabisignals.com
  • License: Educational and personal use only. See the license notes in the workshop files.
  • Copyright: © 2026 Torabi Signals Ltd. All rights reserved.