I want coding for feature extraction for ecg signal
8 views (last 30 days)
Show older comments
Need code for feature extraction for ecg signal.
0 Comments
Answers (1)
Hari
on 28 May 2025 at 7:53
Hi Saranya,
I understand that you want to perform feature extraction on an ECG signal. Feature extraction in ECG signals typically involves identifying key points such as R-peaks, QRS complexes, and other waveform characteristics.
I assume you have an ECG signal already loaded in MATLAB and you want to extract features like R-peaks and QRS duration.
In order to perform feature extraction on an ECG signal, you can follow the below steps:
Load and Pre-process the ECG Signal:
Ensure your ECG signal is loaded and pre-processed for noise reduction, if necessary.
% Assuming 'ecgSignal' is your ECG data and 'fs' is the sampling frequency
ecgSignal = load('your_ecg_data.mat'); % Load your ECG data
fs = 1000; % Example sampling frequency in Hz
Detect R-peaks:
Use the “findpeaks” function to detect R-peaks in the ECG signal.
[~, rPeaks] = findpeaks(ecgSignal, 'MinPeakHeight', 0.5, 'MinPeakDistance', 0.6*fs);
Extract QRS Complex:
Define a window around each R-peak to extract the QRS complex.
qrsWidth = round(0.1 * fs); % QRS width in samples
qrsComplexes = arrayfun(@(r) ecgSignal(max(1, r-qrsWidth):min(length(ecgSignal), r+qrsWidth)), rPeaks, 'UniformOutput', false);
Calculate Features:
Compute features such as QRS duration and R-R intervals.
qrsDurations = cellfun(@length, qrsComplexes) / fs; % QRS duration in seconds
rrIntervals = diff(rPeaks) / fs; % R-R intervals in seconds
Output the Extracted Features:
Display or save the extracted features for further analysis.
fprintf('Average QRS Duration: %.2f seconds\n', mean(qrsDurations));
fprintf('Average R-R Interval: %.2f seconds\n', mean(rrIntervals));
Refer to the documentation of “findpeaks” function to know more about its usage:
Hope this help
0 Comments
See Also
Categories
Find more on ECG / EKG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!