Natasha asked . 2021-01-29

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 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;
This is the resulting frequency response of the filter and the magnitude spectrum of the signal:
 

Butterworth ecg

 
An here the filtered signal vs. the noisy signal:
Butterworth ecg
 
 
 
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.

matlab , signal , signal processing

Expert Answer

John Michell answered . 2024-04-19 20:27:16

Respiratory activity, muscle activity, any number of possibilities. It seems that the EKG was recorded without the benefit of the right-leg reference electrode (erroneously called a ‘ground’), so any activity within the frequency range of the recording equipment could appear.
 
In addition to the bandstop filter you designed, you probably need to use a bandpass filter with a low-frequency passband of 1 Hz and a high-frequency passband of 50 Hz.
This design works:
 
FreqS = 94.3;                                                   % Sampling frequency
fcuts = [0.5 1.0 45 46];                                        % Frequency Vector
mags =   [0 1 0];                                               % Magnitude (Defines Passbands & Stopbands)
devs = [0.05  0.01  0.05];                                      % Allowable Deviations
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,FreqS);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');

figure
freqz(hh, 1, 2^14, FreqS)


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.