Vital-Signs-Detection-and-Estimation / autoEstimation.m
autoEstimation.m
Raw

function [brEst, hrEst] = autoEstimation(br_signal,hr_signal,param)

    b_cut = br_signal;
    h_cut = hr_signal;

    
    bauto = xcorr(b_cut);
    hauto = xcorr(h_cut);

    [bpeaks,~] = findpeaks(bauto);
    [hpeaks,~] = findpeaks(hauto);

    brEst = (length(bpeaks)/2) * 60/(param.endsec - param.startsec);
    hrEst = (length(hpeaks)/2) * 60/(param.endsec - param.startsec);

    N = param.samplerange;
    t = linspace(param.startsec,param.endsec,N);
    figure
    subplot(2,1,1)
    plot(t,bauto(1:N))
    title("Autocorrelated Breathing Signal")

    subplot(2,1,2)
    plot(t,hauto(1:N))
    title("Autocorrelated Heartbeat Signal")

end