Create or Load Signal
In the Live Editor, load a noisy electrocardiogram (ECG) signal into the MATLAB® workspace. Plot the data.
The ECG signal appears noisy. There are several sources of noise that can affect the signal including movement artifacts, high-frequency noise, and power source interference. Interactively design a filter to remove the noise from the signal. In the Live Editor tab, expand the Task list and select Design Filter
to open the task.
Design Lowpass FIR Filter Using Kaiser Window
To remove high-frequency noise, first select a Lowpass FIR filter and specify the Order as 20
. The available options for frequency, magnitude, and algorithm parameters depend on the selected filter response type and filter order.
A lowpass filter removes from an input signal the unwanted frequency content above a specified threshold. In the Specify frequency parameters section, select Cutoff (6dB) frequency
from the Frequency constraints list. When the sample rate is known, you can select Hz
from the Frequency units list. A Sample rate option appears, and you can select a sample rate from the variables in the workspace. In this example, the sample rate is unknown, so specify a normalized cutoff frequency of 0.5
rad/sample.
For an FIR lowpass filter, in the Specify magnitude parameters section, you can specify constraints to control the amount of passband ripple and stopband attenuation. Select Passband ripple and stopband attenuation
from the Magnitude constraints list. Magnitude constraints and filter order can also affect the transition width of the filter.
Select the FIR contrained least-squares
design algorithm. Leave the design options at their default settings.
In the Display filter response section, select Magnitude & phase
and Group delay
to visualize the designed filter response. In the magnitude plot, you can see the level of attenuation in the stopband is at 60 dB. The group delay plot shows a delay of 10 samples and that the filter is linear phase.
Click the arrow below the Show code section to show the generated code for the designed filter. You can copy and paste the code on the command line to edit the filter design specifications manually.
Apply the designed filter to the noisy ECG signal. Account for the delay introduced by the filter and plot the result.
Design Equiripple Bandstop FIR Filter
A medical device like an ECG monitor can be impacted by electromagnetic interference. A power source commonly operates at a frequency of 50 Hz or 60 Hz. For this example, a 60 Hz sinusoid was added as noise to an ECG signal taken from the MIT-BIH Arrhythmia Database [1]. The sample rate is 360 Hz. To remove the noise, open the Design Filter task and design a minimum-order bandstop FIR filter. Change the default filter name to bandstop60Hz
.
Specify the Frequency units as Hz
. To specify a sample rate, enter a value or select a sample rate variable from the list. To appear in the list, a sample rate variable must be saved in the workspace. Create a variable, fs
, and set it equal to 360
Hz, then select fs
from the Sample rate list. Specify the passband and stopband frequency values to attenuate frequencies between 55–65 Hz for a 10 Hz notch filter centered at 60 Hz.
Set the Passband ripple 2 (dB) to 0.5
and increase the Stopband attenuation (dB) to 80
.
The task defaults to an equiripple design method. Display the magnitude and phase responses of the filter.
You can also select Filter information
from the Display filter response section to view additional details about the designed filter.
Load ecg60Hz
into the workspace. The MAT-file contains the original ECG signal with added noise (ecg60
) and the filtered signal (ecgFilt
). Plot both signals to visualize the filter result.