You are on page 1of 2

LAB Answers

Open Mobile Search

Follow

Vote

Filtering ECG signal with stopband filter using Butterworth filter


method
Asked by Gautam Ilango on 3 Jan 2017

Latest activity Answered by Star Strider on 4 Jan 2017

Accepted Answer by Star Strider

210 views (last 30 days)

I am trying to filter out an ECG signal using the eighth order butterworth filter method. I am using a bandstop
filter. Here is the MATLAB Code:

clear;
Data = csvread('ecg_HF_noise.csv',1,0);
signal = Data(:,3)/100000;
N = length(signal);
FreqS = 94.3; % Sampling
frequency
nyqFreq = FreqS/2; % Nyquist frequency
fft_signal = abs(fft(signal));
figure(1); % Plot single-sided
magnitude spectrum (normalized)
x1 = 0:1/(N/2 -1):1;
y1 = fft_signal(1:N/2);
p1 = line(x1,y1);
grid on;
ax1 = gca; % current axes
axis([0 1 0 1]);
xlabel('Normalised frequency [\pi rads/sample]');
ylabel('Magnitude');
[b a] = butter(8, [0.49 0.55], 'stop');
H = freqz(b,a,N/2);
hold on;
x2 = linspace(0,nyqFreq,500);
y2 = abs(H);
ax1_pos = ax1.Position;
ax2 =
axes('Position',ax1_pos,'XAxisLocation','top','YAxisLocation','right','Color','none');
ax2.XLabel.String = 'Frequency [Hz]';
p2 = line(x2,y2,'Parent',ax2,'Color','r'); % Plot frequency
response
title('Magnitude spectrum of signal and frequency response of filter');
axis([0 nyqFreq 0 1]);
legend([p1 p2],'magnitude spectrum','frequency response');
x_filtered = filter(b,a,signal);

hold off;

You might also like