# Filtering ECG signal with stopband filter using Butterworth filter method

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 frequencynyqFreq = 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 axesaxis([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 responsetitle('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;

This is the resulting frequency response of the filter and the magnitude spectrum of the signal:

An here the filtered signal vs. the noisy signal:

Figure 2:

I don’t understand why by rejecting the ca. 24Hz peak, the signal is filtered. What about the noisy part between 0 to 0.4 and the mysterious large peak at the beginning? -When I apply the filter over that region the signal is not filtered. How can that be explained? I had my PC adapter (50Hz) near the sensor during the time of capture of the data.

What might that peak at the beginning with the large amplitude be? The unfiltered signal at the beginning of figure 3 looks normal though.