MATLAB Documentation

Apply Adaptive Noise Canceling to Fetal Electrocardiography

On This Page (4 sections)

Adaptive Noise Canceling for Fetal Electrocardiography in MATLAB

Extracting a fetal electrocardiogram (fECG) from non-invasive abdominal electrodes is a classic biomedical signal processing problem. An electrode placed on the mother's abdomen picks up the weak fetal heartbeat alongside a much stronger maternal heartbeat. Because the maternal signal is 5 to 10 times larger in amplitude and overlaps the fetal QRS complex in both time and frequency, fixed bandpass filters cannot separate the two signals cleanly.

Adaptive noise canceling (ANC) solves this by using a second reference sensor placed on the mother's chest. The chest lead records the maternal ECG with almost no fetal interference. Since the maternal heartbeat travels through tissue before reaching the abdominal sensor, it arrives delayed, attenuated, and phase-shifted. An adaptive filter learns that distortion path and subtracts the maternal component from the abdominal signal, leaving the fetal ECG in the residual error.

How adaptive noise canceling works

The abdominal recording acts as the primary input d(n), which is the sum of the desired fetal signal sfetal(n) and the correlated maternal interference mabd(n). The chest recording x(n) serves as the reference input. An FIR adaptive filter of length M with weight vector w(n) estimates the maternal component at the abdomen:

y(n) = wT(n) · x(n)
e(n) = d(n) − y(n)
w(n+1) = w(n) + μ · e(n) · x(n) / (ε + ||x(n)||2)

In the Normalized Least Mean Squares (NLMS) update above, μ controls the adaptation step size, ε is a small regularization constant that prevents division by zero, and the output error e(n) converges to the clean fetal ECG. Normalizing by the reference signal energy ||x(n)||2 keeps the filter stable even when sharp maternal R-peaks cause sudden jumps in signal power.

Choosing filter order and step size

Picking the right tap length M and step size μ determines how quickly the filter tracks heart-rate changes without distorting the fetal waveform. A tap length between 15 and 35 samples (at a 500 Hz to 1000 Hz sampling rate) is usually enough to model the acoustic and electrical propagation delay through maternal tissue. If μ is too small, the maternal R-peak leaks into the output; if μ is too large, the weights track the fetal signal itself or become unstable.

Parameter Typical range Effect on fECG extraction
Filter order (M) 15 to 35 taps Covers tissue delay and phase shift between chest and abdomen
NLMS step size (mu) 0.05 to 0.25 Balances fast maternal cancellation against low weight jitter
Regularization (eps) 1e-6 Prevents blow-up during quiet baseline intervals

Runnable MATLAB implementation (NLMS filter)

The script below synthesizes a maternal chest ECG, passes it through a simulated tissue distortion filter, adds a faster, lower-amplitude fetal heartbeat, and recovers the fetal ECG using Normalized LMS. It runs in standard MATLAB without requiring extra toolboxes, though you can also swap the loop for dsp.LMSFilter('Method','Normalized LMS') if you have DSP System Toolbox installed.

%% Adaptive Noise Canceling (NLMS) for Fetal ECG Extraction
clear; clc; close all;

fs = 500; % Sampling rate [Hz]
t = (0:1/fs:8-1/fs)'; % 8-second recording
N = length(t);

% 1. Synthetic Maternal Chest ECG (~72 bpm = 1.2 Hz)
m_chest = 1.2 * exp(-((mod(t, 1/1.2) - 0.20) / 0.018).^2) ...
- 0.3 * exp(-((mod(t, 1/1.2) - 0.24) / 0.012).^2);

% 2. Distorted Maternal Component at Abdomen (delay + attenuation)
b_tissue = [0, 0, 0, 0.75, 0.35, -0.15];
m_abd = filter(b_tissue, 1, m_chest);

% 3. Weak Fetal ECG (~150 bpm = 2.5 Hz)
f_true = 0.22 * exp(-((mod(t, 1/2.5) - 0.12) / 0.012).^2);

% Measured abdominal signal (fetal + maternal + sensor noise)
d = f_true + m_abd + 0.02 * randn(N, 1);
x = m_chest + 0.01 * randn(N, 1);

% 4. NLMS Adaptive Filter
M = 20; % Filter tap length
mu = 0.15; % Step size
eps_val = 1e-6;
w = zeros(M, 1);
y = zeros(N, 1);
e = zeros(N, 1);

for n = M:N
x_vec = x(n:-1:n-M+1);
y(n) = w' * x_vec;
e(n) = d(n) - y(n);
w = w + (mu / (eps_val + (x_vec' * x_vec))) * e(n) * x_vec;
end

% 5. Plot Comparison
figure('Color', 'w');
subplot(3,1,1); plot(t, d, 'k'); grid on;
title('Abdominal Recording d(n): Maternal + Fetal ECG'); ylabel('mV');

subplot(3,1,2); plot(t, x, 'b'); grid on;
title('Chest Reference Signal x(n): Maternal ECG Only'); ylabel('mV');

subplot(3,1,3); plot(t, e, 'r'); hold on; plot(t, f_true, 'g--'); grid on;
title('Recovered Fetal ECG e(n) vs. True Fetal Signal');
xlabel('Time [s]'); ylabel('mV');
legend('ANC Output e(n)', 'True Fetal ECG');

When working with clinical recordings from the PhysioNet Abdominal and Direct Fetal ECG Database, start by removing baseline wander with a 0.5 Hz high-pass filter and 50/60 Hz powerline hum with a notch filter before feeding the channels into the NLMS block. If you are building a real-time Simulink model, comparing LMS against Recursive Least Squares (RLS) is a common benchmark for thesis and coursework submissions.

If you need help tuning adaptive filter convergence, integrating dsp.LMSFilter into a Simulink block diagram, or processing multi-channel PhysioNet ECG data, explore our MATLAB assignment help services or request custom Simulink signal processing support.