Filtring real ECG signals
31 次查看(过去 30 天)
显示 更早的评论
I recorded a real ECG using Analog Discovery and I'm trying to filter the ECG using four filters
1-BandpassBessel order 1 iir bandpass filter
2-Bandpass (actually bandstop filter)
Bandstop filter
3-Averaged
Moving average filter of length 10
4-Smoothing Filter
Moving average filter of length 24
The results were not correct and I don't know why
Here is my code :
clear all;close all;clc;
daqlist("digilent")
dq = daq("digilent")
ch_in = addinput(dq, "AD1", "1", "Voltage");
ch_in.Name = "AD1_1_in";
%rate = 100e3; % frequency = 300KHz
%dq.Rate = rate;
ch_in.Range = [-2.5 2.5];
[data, startTime] = read(dq, seconds(5));
subplot(4,1,1);
plot(data.Time, data.AD1_1_in);
xlabel('Time (s)');
ylabel('Voltage (V)');
title(['Clocked Data Triggered on: ' datestr(startTime)]);
subplot(4,1,2);
Fs = 2000;
LC1 = 1;
UC1 = 34;
n = 1;
[b,a]=besself(n,[LC1,UC1]/(Fs/2), 'bandpass');
w = linspace(0,pi,1000);
H = freqz(b,a,w);
plot(w,abs(H));
subplot(4,1,3);
y = filter(b,a,data.AD1_1_in);
plot(data.Time,y);
subplot(4,1,4);
LC2 = 15;
UC2 = 120;
n = 20;
[b,a]=besself(n,[LC2,UC2]/(Fs/2), 'stop');
y1 = filter(b,a,y);
plot(data.Time,y1);
2 个评论
Mathieu NOE
2022-11-24
hi
it would be better if you could save your raw data first in a mat file then share it along the code
or is the issue the data acquisition itself ?
Star Strider
2022-11-24
Bessel filters cannot be implemented as digital filters and retain their phase-neutral properties. That only works with analog implementations. Use a different design.
The MATLAB filtfilt function provides zero-phase filtering for all digital filters. The most computationally efficient filters are elliptic filters.
回答(1 个)
Sachin Lodhi
2023-9-26
Hi Abdulaziz,
Based on my understanding, it appears that you are facing unexpected results as a consequence of inaccurate implementation of the filters. In MATLAB, the 'filter' function is designed to apply the filter to the entire input signal. However, in your code, it seems that you are directly passing 'data.AD1_1_in', which represents the vector of recorded ECG data, as the argument to the 'filter' function.
It is important to note that the incorrect results may be attributed to the improper setting of the initial conditions of the filter. To ensure the correct application of the filter, I highly recommend utilizing the 'filtfilt' function. This function performs zero-phase filtering and effectively handles the initial conditions, ensuring accurate results.
For more detailed information on how to use the ‘filtfilt’ function correctly, I suggest referring to the following documentation:
I hope you find this information useful.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Frequency Transformations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!