How to filter ECG signal in matlab

53 visualizaciones (últimos 30 días)
Ahmed Rayhan
Ahmed Rayhan el 15 de Ag. de 2023
Comentada: Image Analyst el 15 de Ag. de 2023
Hello good people please help me out as I am feeling helpless here, I have to Design a digital filter using MATLAB which can separate noise from ECG signal (Data set is provided). I have to optimize the parameter: stop band attenuation, pass band ripple,
width of transition band and filter kernel. I am not allowed to use any inbuilt functions of FIR filter or filter design toolbox during demonstration.
The design should be tested to
i. Verify the removal of noise by frequency analysis.
ii. Verify the optimization of mentioned parameters by time domain and frequency domain analysis of filter characteristics.
I am asked to
my ECGdata contains 4 variables: x, t, noisyECG, noisyECG_withTrend. Among these variable x, noisyECG and noisyECG_withTrend is 1 column and 2000 rows while t is 2000 columns and 1 row.
The database contains 310 ECG recordings, obtained from 90 persons. Each recording contains:
ECG lead I, recorded for 20 seconds, digitized at 500 Hz (sampling frequency) with
12-bit resolution over a nominal ±10 mV range.
10 annotated beats (unaudited R- and T-wave peaks annotations from an automated
detector)
I wrote the below code but it doesn't run and i get this error:
"Index in position 1 exceeds array bounds (must not exceed 1).
Error in Untitled (line 8)
signal1 = data(L+N,:);"
% Load the ECG Data
data = load('ECGData.mat');
L = 1;
M = 7;
N = 7;
% Select the Signals
signal1 = data(L+N,:);
signal2 = data(5*(M+N),:);
% Define filter parameters
order = 10; % Order of the filter
fc = 100; % Cut-off frequency
% Compute normalized cut-off frequency
wc = fc/(500/2);
% Design filter using window method
n = 0:order;
h = wc/pi * sinc(wc*(n - order/2)); % Ideal impulse response
w = hamming(order+1); % Hamming window
h = h .* w'; % Actual impulse response
% Apply the Filter
filtered_signal1 = conv(signal1, h);
filtered_signal2 = conv(signal2, h);
% Analyze the Results
% Time domain
figure;
subplot(2,1,1);
plot(signal1);
title('Original Signal 1');
subplot(2,1,2);
plot(filtered_signal1);
title('Filtered Signal 1');
% Frequency domain
figure;
subplot(2,1,1);
plot(abs(fft(signal1)));
title('Frequency Spectrum of Original Signal 1');
subplot(2,1,2);
plot(abs(fft(filtered_signal1)));
title('Frequency Spectrum of Filtered Signal 1');
% Repeat for signal2
% Time domain
figure;
subplot(2,1,1);
plot(signal2);
title('Original Signal 2');
subplot(2,1,2);
plot(filtered_signal2);
title('Filtered Signal 2');
% Frequency domain
figure;
subplot(2,1,1);
plot(abs(fft(signal2)));
title('Frequency Spectrum of Original Signal 2');
subplot(2,1,2);
plot(abs(fft(filtered_signal2)));
title('Frequency Spectrum of Filtered Signal 2');
  1 comentario
Image Analyst
Image Analyst el 15 de Ag. de 2023
Can you attach your data and code to read it in with the paperclip icon after you read this:

Iniciar sesión para comentar.

Respuestas (0)

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by