ECG Segmentation and Classification using PQRST
20 次查看(过去 30 天)
显示 更早的评论
Hello MATLAB community,
I'm working on ECG classification using MATLAB, and my data is stored in CSV format with 13 columns (time + 12 leads). I'm interested in extracting PQRST segments using the segmentation method described in this MATLAB code: ECG Segmentation and Filtering.
I have a few questions regarding preprocessing:
- Should I apply low-pass filters to all recordings to enhance signal quality?
- I intend to retain various types of noise in the data to ensure model robustness. What are your recommendations on managing noise while preserving the integrity of PQRST segments?
Additionally, I'm curious about segmentation approach:
- Should I perform segmentation separately for each of the 12 leads, or should I merge them before segmentation? What would be the pros and cons of each approach?
Here an example of an ECG data:
Any insights or suggestions on adapting the segmentation method and handling data preprocessing would be greatly appreciated. Thank you!
0 个评论
采纳的回答
Diego Caro
2024-6-30
Should I apply low-pass filters to all recordings to enhance signal quality? ECG frequencies fall in the range of 0.5 to 150 Hz. If your sampling rate is above 300 Hz, you should first add a lowpass filter with cutoff frequency at 150 Hz. However, you should always take a look at the spectrum of your signal to detect if it has unwanted artifacts. In case you decide to filter your signals, you must filter them all with the same filter to mantain uniformity in your results.
What are your recommendations on managing noise while preserving the integrity of PQRST segments? It all comes to visualizing a clean spectrum. Take a look at the following code.
ecg = ecg_signal % One lead only
fs = 125; % Sample rate
t = (0:numel(ecg)-1)/fs;
figure
subplot(2,1,1)
plot(t,ecg)
title('Raw ECG')
xlabel('Time (s)')
ylabel('Amplitude')
xlim([0 5])
subplot(2,1,2)
pspectrum(ecg,fs,'Leakage',1)
title('Spectrum')
This ECG seems to have line noise, based on the spike that shows at 60 Hz. The other spikes are due to the fundamental frequency (FF) of the ECG ranging from 1 to 1.67 Hz. The frequency at which the first spike appears is the FF and can be used to obtain the heart rate (HR = 60*FF). The other spikes show FF harmonics, which are just repetitions of the first spike that are spaced over the spectrum with a uniform separation of its FF.
In other words, the FF of the figure above is 1.5 Hz, so the next spikes appear at 3, 4.5, 6 Hz and so on. You should see its amplitude reduce as the frequency increases, so you must not filter out these spikes.
In this case, it is recommended to apply a lowpass filter with a cutoff frequency below 60 Hz, or a bandstop filter rejecting this unwanted frequency.
To compare both
ecg_filt = lowpass(ecg,50,fs);
figure
subplot(2,1,1)
plot(t,ecg_filt)
title('Filtered ECG (Lowpass fc = 50 Hz)')
xlabel('Time (s)')
ylabel('Amplitude')
xlim([0 5])
subplot(2,1,2)
pspectrum(ecg_filt,fs,'Leakage',1)
title('Spectrum')
ecg_filt2 = bandstop(ecg,[59 61],fs);
figure
figure
subplot(2,1,1)
plot(t,ecg_filt2)
title('Filtered ECG (Bandstop fp = 60 Hz)')
xlabel('Time (s)')
ylabel('Amplitude')
xlim([0 5])
subplot(2,1,2)
pspectrum(ecg_filt2,fs,'Leakage',1)
title('Spectrum')
As you can see, after filtering with both types of filter, the quality of the signal improves a lot, and the PQRST waves appear properly in both cases (this is a healty subject). It's up to you to determine if your signals need extra filtering or not.
Should I perform segmentation separately for each of the 12 leads, or should I merge them before segmentation? What would be the pros and cons of each approach? You should apply the segmentation individually for each of the leads of your interest. Each lead considers a different electrode placement at the moment of capturing the ECG, and these changes in position translates into obtaining different information from each of them. There are no pros but cons to merging the 12 leads into one signal. You loose relevant information. In certain pathologies, some waves have abnormal amplitudes, and these changes are best appreciated only in certain leads. This is why the ECG is taken with many leads in the first place.
Appart from that, you should keep the procedure of segmentation uniform, so that your segmentations come out consistent.
Regards,
Diego.
9 个评论
Umar
2024-7-5
Hi Rawaa,
You asked, i use this method : for m = 1:size(leads, 2) denoised_leads(:, m) = wdenoise(leads(:, m), 'Wavelet', 'bior3.1', 'DenoisingMethod', 'SURE', 'ThresholdRule', 'Soft', 'NoiseEstimate', 'LevelDependent'); end here some examples , is that true ?
The code snippet you provided is correct for performing wavelet denoising in MATLAB using the 'wdenoise' function. It applies the 'bior3.1' wavelet, uses the 'SURE' denoising method, employs a 'Soft' threshold rule, and estimates noise in a level-dependent manner. The loop iterates over each column of the 'leads' matrix, denoising them individually. If your intention is to denoise each column of 'leads' using the specified wavelet and denoising parameters, then the code is appropriate.
更多回答(3 个)
Umar
2024-6-30
Hi Rawaa,
For ECG data preprocessing, try to apply low-pass filters which will enhance signal quality by removing high-frequency noise. However, retaining some noise types can improve model robustness. To manage noise while preserving PQRST integrity, consider using adaptive filters or wavelet denoising techniques.
Regarding segmentation, you can choose to segment each of the 12 leads separately or merge them before segmentation. Segmentation per lead allows for lead-specific analysis but may require more computational resources. Merging leads simplifies processing but may overlook lead-specific characteristics. Experiment with both approaches to determine the best fit for your dataset and analysis goals.
Remember to validate the segmentation method's effectiveness by comparing results with ground truth annotations.
Hope this will help resolve your problem.
0 个评论
Umar
2024-7-5
Hi Rawaa,
I have already read the technical articles for both of them, so let me delve into the specifics of the bior3.1 and sym4 wavelet families to help you make an informed decision.
bior3.1 Wavelet Family
The bior3.1 wavelet belongs to the Biorthogonal wavelet family. Biorthogonal wavelets have the advantage of providing a good compromise between time and frequency localization. The bior3.1 wavelet has three vanishing moments in the wavelet function and one vanishing moment in the scaling function. This property makes it suitable for applications where preserving sharp transitions in the signal is essential. The bior3.1 wavelet is known for its ability to capture abrupt changes in the signal efficiently.
sym4 Wavelet Family
On the other hand, the sym4 wavelet is part of the Symlet wavelet family. Symlet wavelets are designed to be symmetric with a compact support, making them suitable for denoising applications and signal compression. The sym4 wavelet, in particular, has four vanishing moments in the wavelet function, allowing it to represent polynomial signals accurately. It is known for its effectiveness in denoising applications where preserving signal smoothness is crucial.
Choosing the Best Wavelet Family
To determine the best wavelet family between bior3.1 and sym4, you need to consider the specific characteristics of your signal and the requirements of your signal processing task. If your signal contains sharp transitions or discontinuities that need to be preserved, the bior3.1 wavelet may be more suitable due to its ability to capture abrupt changes effectively. On the other hand, if your signal is smooth and you are focusing on denoising or compression tasks, the sym4 wavelet from the Symlet family might be a better choice.
Again, the final decision needs to be made by you. I still wish you good luck with this project. Hope, you get A plus.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Multiresolution Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!