My calculation for respiratory rate shows the same bpm for my 3 waveforms.
4 views (last 30 days)
Show older comments
I need to find the respiration rate as part of my project. My code is the same for each of my waveforms, but when I click run to calculate it I keep getting 90 bpm and I know they are not supposed to all equal 90. The data I have is 3 1000x1 matrix filled with correlation values ranging from 0-1. Below is the part of the code that I am trying to use to calculate respiration rate:
% %PEAK FINDING
neg_peaks=islocalmin(Corr_smooth);
figure;
plot(times, Corr_smooth, times(neg_peaks),Corr_smooth(neg_peaks), '*r');
t=(1:length(Corr_smooth))/Fs;
time_diffs=diff(t);
resp_rate=mean(1./time_diffs);
disp(['The respiration rate is ' num2str(resp_rate) ' bpm'])
My Fs=90 and I have to find the resp. rate using the negative peaks so that's why im not using findpeaks.
Any help is appreciated!
0 Comments
Answers (2)
Voss
on 6 Nov 2023
You are calculating the average of the inverse of the differences of t, but t is essentially just a vector of all time indices:
t = (1:length(Corr_smooth))/Fs;
so diff(t) is 1/Fs everywhere, and of course mean(1./diff(t)) is Fs.
I think you should be using the times where the local minima were found?
t = times(neg_peaks);
12 Comments
Voss
on 7 Nov 2023
% load the data from the mat files:
files = dir('*.mat');
for ii = 1:numel(files)
S(ii) = load(files(ii).name);
end
Fs = 90;
figure;
for ii = 1:3
Corr = S(ii).Corr;
% here I make up a method to calculate Corr_smooth from Corr:
Corr_smooth = movmedian(Corr,7);
% some additional parameters to islocalmin are required:
neg_peaks = islocalmin(Corr_smooth,'MinProminence',0.05,'MinSeparation',45);
times = (1:numel(Corr_smooth))/Fs;
subplot(3,1,ii)
plot(times, Corr_smooth, times(neg_peaks),Corr_smooth(neg_peaks), '*r');
t = times(neg_peaks);
resp_rate=mean(60./diff(t)); % here I assume t is in seconds
title([num2str(resp_rate) ' bpm'])
end
Star Strider
on 7 Nov 2023
Perhap;s this —
LD1 = load('USaverageImageIntensity_R1.mat');
Corr(:,1) = LD1.Corr;
LD2 = load('USaverageImageIntensity_R2.mat');
Corr(:,2) = LD2.Corr;
LD3 = load('USaverageImageIntensity_R3.mat');
Corr(:,3) = LD3.Corr;
Fs = 90;
t = linspace(0, size(Corr,1)-1, size(Corr,1)).'/Fs;
for k = 1:size(Corr,2)
[vys,vlocs] = findpeaks(-Corr(:,k), 'MinPeakProminence',min(Corr(:,k))/10, 'MinPeakDistance',25);
vysc{k} = [vys vlocs];
end
figure
plot(t, Corr)
grid
xlabel('Time (s)')
ylabel('Amplitude')
figure
tiledlayout(size(Corr,2),1)
for k = 1:size(Corr,2)
nexttile
plot(t, Corr(:,k))
hold on
plot(t(vysc{k}(:,2)), -vysc{k}(:,1), 'vr')
hold off
grid
xlabel('Time (s)')
ylabel('Amplitude')
RR = mean(1./diff(t(vysc{k}(:,2))))*60;
title("Corr "+k)
ylim([min(ylim) max(ylim)*1.25])
text(3, 1.15, sprintf('Respiratory Rate = %.1f / minute', RR))
end
Make appropriate changes to get the desired result.
.
0 Comments
See Also
Categories
Find more on Time-Frequency Analysis 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!

