SNR vs Amplitude plot for ECG Lead

22 vues (au cours des 30 derniers jours)
Elzbieta
Elzbieta le 19 Nov 2024 à 10:52
Modifié(e) : Peter Perkins il y a environ 8 heures
Hello,
How to plot the figure SNR vs Amplitude for each ECG Lead separately:
%----available amplitudes
amplitudes = {'0.05', '0.10', '0.15', '0.20', '0.25', '0.30', '0.35',...
'0.40', '0.45', '0.50', '1.00', '1.50', '2.00', '2.50', '3.00',...
'3.50', '4.00', '4.50', '5.00', '5.50' }
%heartRates = {'30bpm', '40bpm', '45bpm', '60bpm', '80bpm', '90bpm', '100bpm'}
%heartRates = {'120bpm', '140bpm', '160bpm', '180bpm', '200bpm', '220bpm',...
% '240bpm', '260bpm', '280bpm', '300bpm'}
Fs = 1000;
s = struct;
% Build table
T = table();
SNR = {}
Leads = ["I" "II" "V_"+(1:6)];
ECGLeads = {ecgData.leadI, ecgData.leadII,...
ecgData.V1, ecgData.V2, ecgData.V3,...
ecgData.V4, ecgData.V5, ecgData.V6};
%----get amplitude/heart rate parameter from text file
file = fullFileName
field=textread(file,'%s',7,'delimiter','\n')
%-------for each amplitude parameters
for kleads = 1:length(ECGLeads)
for iamp = 1:length(amplitudes)
if (find(~cellfun(@isempty,strfind(field,amplitudes{iamp}))==true))
% Define parameters
total_samples = size(rawData,1);
sampling_frequency = 1000; % in Hz
duration = 3; % in seconds
% Generate a time vector for the entire signal
t = (0:total_samples-1) / sampling_frequency;
% Generate a e sigsamplnal (for example, a sine wave)
signal = ECGLeads{kleads}; %
% Extract sample of signal
sample_duration = duration; % in seconds
sample_samples = sample_duration * sampling_frequency;
sample_signal = signal(1:sample_samples);
sample_time = t(1:sample_samples);
sample_ecg{kleads} = sample_signal;
%s.(amplitudes{iamp}).(sample_ecg{kleads}) = sample_signal;
%calculate snr
SNR{iamp} = calc_snr(sample_ecg{kleads}, Fs)
end%iamp
end%if
tiledlayout(2, 4, TileIndexing='columnmajor')
for iamp = 1:length(amplitudes)
% snr_Min = min(cell2mat(SNR{:}));
% snr_Max= min(cell2mat(SNR));
% sample_snr;
sample_amplitude = vertcat(amplitudes{:});
nexttile
plot(amplitudes, SNR{iamp});
xlabel('Amplitude (mV)');
ylabel('SNR (dB)');
title(Leads{kleads}, [amplitudes, SNR ]);
% xlim([0 3])
% %ylim([-4.5e-03 50e-04])
% ylim([snr_Min snr_Max])
output_fig_snr = [path_data_fig, Leads{kleads},'.fig']
output_fig_snr_jpg = [path_data_fig, Leads{kleads},'.jpg']
saveas(gcf, output_fig_snr, 'fig')
saveas(gcf, output_fig_snr_jpg, 'jpg')
end %iamp
end %if amp
end %kleads

Réponses (2)

Raghava S N
Raghava S N le 20 Nov 2024 à 9:48
To plot the SNR vs Amplitude graph for each lead separately, you may follow the below steps.
  • Move this command -
tiledlayout(2, 4, 'TileIndexing', 'columnmajor');
before the for loop -
for kleads = 1:length(ECGLeads)
The “tiledlayout function only needs to be called once to declare a tiled figure. For more information about the “tiledlayout” function, refer to this link - https://www.mathworks.com/help/matlab/ref/tiledlayout.html#:~:text=polarscatter(theta%2Crho)-,Reconfigure%20Content%20in%20Previous%20Tile,-Open%20in%20MATLAB.
for kleads = 1:length(ECGLeads)
after SNR is calculated for all amplitudes-
plot(cellfun(@str2double, amplitudes), cell2mat(SNR))
Hope this helps!

Peter Perkins
Peter Perkins il y a environ 8 heures
Modifié(e) : Peter Perkins il y a environ 8 heures
Elzbieta, I have not read your code closely but it seems very likely that stackedplot on a table or timetable will do what you want.

Community Treasure Hunt

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

Start Hunting!

Translated by