Build DEE superposition graphs

2 views (last 30 days)
Mariana
Mariana on 6 Jan 2024
Answered: UDAYA PEDDIRAJU on 15 Jan 2024
The following code seems to generate correctly the graphs that show the DEE superposition of Korotkoff sounds for 7 pressure measures. However, only those graphs end up very small. Why is that?
close all
clear
% Cargar datos desde el archivo korotkoff.mat
load korotkoff.mat
fc = 20; % Frecuencia de corte
fs = 500; % Frecuencia de muestreo
fn = fs / 2; % Frecuencia de Nyquist
order = 2; % Orden del filtro
NFFT=pow2(10);
% Inicializa una matriz para alamcenar las DEEs de cada sonido
allDEEs = zeros(floor((NFFT+1)/2), 7);
% Cores específicas para cada sonido
segmentoColores = lines(9);
% Diseño del filtro pasa altos Butterworth
[bfpa, afpa] = butter(order, fc / fn, 'high');
% Filtrar la señal usando el filtro pasa altos
sonidoFiltrado = filtfilt(bfpa, afpa, sons);
N=length(ecg2);
t=(0:N-1)/fs;
% Marcas R del ECG:
R = detecrc(ecg2);
%Gráficos para ECG, Presión y Sonidos
figure(1),clf
subplot 311
plot(t,ecg2)
axis tight
xlabel('Time (s)')
ylabel('ECG with R marks')
hold on
for i=1:length(R)
plot(R(i)*[1 1]/fs,ylim,'--r')
end
hold off
subplot 312
plot(t,pressio)
axis tight
xlabel('Time (s)')
ylabel('Pressure (mmHg)')
subplot 313
plot(t,sonidoFiltrado)
axis tight
xlabel('Time (s)')
ylabel('Korotkoff sounds')
intervalos = [
[6.5 13.5];
[40 46.5];
[58 66.5];
[78 86];
[94.5 103];
[111.5 119];
[137 143.5];
];
% Loop para cada una de las 7 medidas
for medida = 1:7
% Atribuir los valores del intervalo actual
intervalo_atual = intervalos(medida, :);
inicio_del_intervalo(medida) = intervalo_atual(1);
fin_del_intervalo(medida) = intervalo_atual(2);
epoch = [inicio_del_intervalo(medida) fin_del_intervalo(medida)];
t_i = t(t >= epoch(1) & t <= epoch(2));
ecg_i = ecg2(t >= epoch(1) & t <= epoch(2));
sons_i = sonidoFiltrado(t >= epoch(1) & t <= epoch(2));
pressio_i = pressio(t >= epoch(1) & t <= epoch(2));
R_i = R(R >= epoch(1) * fs & R <= epoch(2) * fs);
figure(medida),clf
subplot 311
plot(t_i,ecg_i)
axis tight
xlabel('Time (s)')
ylabel('ECG with R marks')
hold on
for i=1:length(R_i)
plot(R_i(i)*[1 1]/fs,ylim,'--r')
end
hold off
subplot 312
plot(t_i,pressio_i)
axis tight
xlabel('Time (s)')
ylabel('Pressure (mmHg)')
subplot 313
plot(t_i,sons_i)
axis tight
xlabel('Time (s)')
ylabel('Korotkoff sounds')
sgtitle(['Medida' num2str(medida)])
% Análisis de los sonidos de Korotkoff
figure(medida+8)
fmean = [];
fmed = [];
for i=1:length(R_i)-1
[~,posmax]=max(sonidoFiltrado(R_i(i):R_i(i+1)));
muestras=R_i(i)+posmax-1+(-0.05*fs:0.07*fs);
x=sonidoFiltrado(muestras);
subplot(length(R_i)-1,2,2*i-1)
plot(t(muestras),x)
axis tight
xlabel('Time (s)')
ylabel(['Sound ' num2str(i)])
% Estimación DEE
X=fft(x,NFFT);
aX2=abs(X).^2;
f=(0:1/NFFT:(NFFT-1)/NFFT)*fs;
P=aX2(f<fn);
f=f(f<fn);
%Calcular frecuencias media y mediana de cada medida de presión
[fmean(i), fmed(i)] = fmnmd(P(:), f(:));
subplot(length(R_i)-1,2,2*i)
plot(f,P)
hold on
plot(fmean(i)*[1 1],ylim,'g--')
plot(fmed(i)*[1 1],ylim,'r--')
hold off
xlim([25 150])
xlabel('Frequency (Hz)')
ylabel(['DEE of s' num2str(i)])
if i==(length(R_i)-1)
legend('DEE','fmean','fmed')
% Normalizar DEE
P_normalizada = P / sum(P); % Normalizar para que la suma sea 1
% Armazenar todas as DEEs normalizadas
allDEEs(:, i) = P_normalizada;
% Calcular índice de cor com base no número real de sonidos
indiceCor = rem(i-1, size(segmentoColores, 1)) + 1;
% Superponer las curvas normalizadas de DEE
figure(medida+15)
subplot(length(R_i)-1,2,2*i)
hold on
plot(f, P_normalizada, 'color', segmentoColores(i, :)) % Usar un color aleatorio
hold off
end
end
sgtitle(['Medida' num2str(medida)])
%Gráfico de las frecuencias medias y medianas
figure(medida+22),clf
plot(fmean,'-o')
hold on
plot(fmed,'-*')
hold off
legend('fmean','fmed')
xlabel('Sonidos ')
ylabel('Frecuencia (Hz)')
sgtitle(['Medida' num2str(medida)])
end

Answers (1)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU on 15 Jan 2024
Hi Mariana,
The graphs may appear small due to the default figure size or the “subplot” configuration. To make the graphs larger, you can adjust the “figure” size programmatically with the following code:
figure(medida),
set(gcf, 'Position', [100, 100, 800, 600]); % Modify [100, 100, 800, 600] as per your requirement.
Place this code just before the “figure(medida)” line inside the loop to resize each figure. Adjust the [100, 100, 800, 600] values to set the position and size of the figure window to your preference.
You can refer to the documentation to know more about the “set” function: https://www.mathworks.com/help/matlab/ref/set.html.
I hope this helps you!

Community Treasure Hunt

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

Start Hunting!