Abstract:
This paper presents the design and implementation of a finite impulse response (FIR) digital filter for noise
removal from a synthetic ECG signal using MATLAB. A low-pass filter is designed using the windowing
method based on an ideal sinc function. Three window functions—Hamming, Hanning, and Blackman—are
applied and compared. The filter is implemented without using built-in FIR design functions. Performance is
evaluated in time and frequency domains, and the effect of different windows on stop-band attenuation,
pass-band ripple, and transition width is analyzed.
I. Introduction:
Electrocardiogram (ECG) signals are often corrupted by noise such as powerline interference and high-
frequency disturbances. Digital filtering is a standard technique for improving signal quality.
This work focuses on designing a low-pass FIR filter to remove 50 Hz noise from an ECG signal. The filter
is implemented manually using the windowing method, avoiding MATLAB’s built-in filter design tools. The
study also compares different window functions to evaluate their impact on filter performance.
II. Theoretical Background
A. FIR Filter Design Using Window Method
An ideal low-pass filter impulse response is given by:
Fix spacing, brackets, and scaling:
{
2fc
, n=α
Fs
( )
h d [n]= 2 π f c (n−α )
sin
Fs
¿ , n≠ α
π (n−α )
(fc): cutoff frequency
(Fs): sampling frequency
M
α=
2
(M): filter order
Since the ideal impulse response is infinite, it is truncated using a window function:
h[n]=hd[n]⋅w[n]
B. Window Functions
Hamming Window:
w [n]=0.54−0.46 cos ( 2Mπn ) , 0 ≤n ≤ M
Hanning Window:
Page | 1
w [n]=0.5−0.5 cos ( 2Mπn ), 0 ≤ n ≤ M
Blackman Window
w [n]=0.42−0.5 cos ( 2Mπn )+ 0.08 cos ( 4Mπn ) , 0≤ n ≤ M Each window provides a different trade-off between
main-lobe width (transition band) and side-lobe attenuation (noise suppression).
III. Methodology
A. Signal Generation
A synthetic ECG-like signal is generated as:
x(t)=sin(2π⋅1t)+0.5sin(2π⋅2t)
B. Noise Addition
Powerline interference at 50 Hz is added:
n(t)=0.7sin(2π⋅50t)
xnoisy(t)=x(t)+n(t)
C. Filter Design Parameters
TABLE I
FILTER DESIGN PARAMETERS.
Parameter Value
Sampling Frequency (Fs) 500 Hz
Cutoff Frequency (fc) 5 Hz
Filter Order (M) 40
D. Filter Implementation
1. Compute ideal sinc-based impulse response
2. Apply window functions (Hamming, Hanning, Blackman)
3. Normalize coefficients:
h[n]
h [n ]= M
4. Perform convolution:
∑ h [k ]
k=0
M
y [ n ] =k =∑ h[k ] x [n−k ]
k=0
Page | 2
IV. Results and Analysis
A. Time Domain Analysis
The noisy ECG signal exhibits rapid oscillations superimposed on the low-frequency waveform,
corresponding to high-frequency interference. After filtering, all three window-based FIR filters
successfully suppress these oscillations. The Blackman window produces the smoothest output due to its
superior stop-band attenuation, while the Hamming window provides a balanced response. The Hanning
window shows slightly less attenuation, resulting in minor residual variations.
The noisy signal shows high-frequency oscillations due to 50 Hz interference.
After filtering:
o The signal becomes smoother
o High-frequency noise is significantly reduced
o Underlying ECG waveform is preserved
Among the windows:
Blackman gives the smoothest output
Hamming provides a balance
Hanning shows slightly more residual noise
Fig. 1. Time-domain representation of noisy ECG signal and filtered outputs using Hamming, Hanning, and Blackman
window-based FIR filters.
B. Frequency Domain Analysis
Page | 3
As shown in Fig. 2, the frequency spectra of the filtered signals exhibit strong attenuation of high-frequency
components. The dominant energy is concentrated near the low-frequency region (1–2 Hz), while the 50 Hz
noise component is effectively suppressed for all three windowing methods.
Original signal contains peaks at 1 Hz and 2 Hz
Noise appears as a strong component at 50 Hz
Filtered signals show:
o Strong attenuation at 50 Hz
o Preservation of low-frequency components
Fig. 2. Frequency spectrum of filtered ECG signal using Hamming, Hanning, and Blackman window-based FIR
filters.
B. Comparison of Window Performance
TABLE II
COMPARISON BETWEEN WINDOW PERFORMANCE
Window Stop-band Attenuation Transition Width Ripple
Hamming Moderate Moderate Low
Hanning Lower attenuation Wider Moderate
Blackman Highest attenuation Widest Very low
V. Discussion
The results demonstrate that window selection significantly affects filter performance:
Blackman window provides superior stop-band attenuation but at the cost of a wider transition
band.
Page | 4
Hamming window offers a practical balance between attenuation and transition sharpness.
Hanning window is less effective in suppressing high-frequency noise.
The chosen cutoff frequency (5 Hz) effectively removes 50 Hz noise while preserving the signal of interest.
Increasing the filter order would further improve attenuation but increase computational complexity.
VI. Conclusion
A window-based FIR low-pass filter was successfully designed and implemented to remove 50 Hz noise
from an ECG signal. The use of different window functions demonstrated clear trade-offs in filter
performance. The Blackman window achieved the best noise suppression, while the Hamming window
provided a balanced design. The results validate the effectiveness of manual FIR filter design using
fundamental signal processing techniques.
References
[1] A. V. Oppenheim and R. W. Schafer, Discrete-Time Signal Processing, 3rd ed. Pearson, 2010.
[2] S. K. Mitra, Digital Signal Processing: A Computer-Based Approach, 4th ed. McGraw-Hill, 2011.
[3] J. G. Proakis and D. G. Manolakis, Digital Signal Processing: Principles, Algorithms, and Applications,
4th ed. Pearson, 2007.
[4] R. Rangayyan, Biomedical Signal Analysis, IEEE Press, 2002.
Appendix:
MATLAB Code:
clc;
clear;
close all;
%% Step 1: ECG Signal
Fs = 500;
t = 0:1/Fs:5;
ecg = sin(2*pi*1*t) + 0.5*sin(2*pi*2*t);
%% Step 2: Add noise (50 Hz)
noise = 0.7*sin(2*pi*50*t);
noisy_signal = ecg + noise;
%% Step 3: Filter Design Parameters
M = 40;
fc = 5;
n = 0:M;
Page | 5
alpha = M/2;
% Ideal sinc filter
hd = zeros(1, M+1);
for i = 1:M+1
if (n(i) == alpha)
hd(i) = 2*fc/Fs;
else
hd(i) = sin(2*pi*fc*(n(i)-alpha)/Fs)/(pi*(n(i)-alpha));
end
end
%% Step 4: Windows
% Hamming Window
w_hamming = 0.54 - 0.46*cos(2*pi*n/M);
% Hanning Window
w_hanning = 0.5 - 0.5*cos(2*pi*n/M);
% Blackman Window
w_blackman = 0.42 - 0.5*cos(2*pi*n/M) + 0.08*cos(4*pi*n/M);
%% Step 5: Apply windows
h1 = hd .* w_hamming;
h2 = hd .* w_hanning;
h3 = hd .* w_blackman;
% Normalize
h1 = h1 / sum(h1);
h2 = h2 / sum(h2);
h3 = h3 / sum(h3);
%% Step 6: Filtering
y1 = conv(noisy_signal, h1, 'same');
y2 = conv(noisy_signal, h2, 'same');
y3 = conv(noisy_signal, h3, 'same');
figure;
Page | 6