How can create a function with floating median?

9 Ansichten (letzte 30 Tage)
Hello, I have a data with 24 hour continuous RR interval (distance between consecutive heart beats)data and i am trying to create a function that would obtain floating averages for different time durations. Ideally i would like to have a floating median rather than average since the data is non normally distributed. I am having hard time for some reason to create median float. I was wondering if some one would be able to help me out in changing the average float function to median float function. Thanks Tamil
function [avge,stdeviation,pnts,timesampl]=avgfloat(data,timestep,tstart)
% timestep is a vector containing the series of time intervals of interest
% in hr (converted to seconds)
timestep=timestep*3600;
% data is the data
% figure out how many timesteps were entered
l=length(timestep);
% calculate total time elapsed (s) during test (ignoring first data point)
time=zeros(length(data),1);
for i=2:length(data)
time(i)=time(i-1)+data(i);
end
% calcuate number of given time intervals in test
pntstop=floor(time(length(time))./timestep);
for i=1:l
% initialize start variable
strt=1;
for j=1:pntstop(i)
% find index of end of next timestep
n=find(time>=timestep(i)*j,1);
% find number of points that includes
pnts{i}(j)=n-strt+1;
% find average over that time interval
avge{i}(j)=sum(data(strt:n))/length(data(strt:n));
% find standard deviation over that time interval
stdeviation{i}(j)=std(data(strt:n));
% define what time range the sample represents
timesampl{i}(j)=time(floor((n+strt)/2))+tstart*3600;
% update start variable
strt=n+1;
% shift data to align with hours of day
if timesampl{i}(j)>=24*3600
timesampl{i}(j)=timesampl{i}(j)-24*3600;
elseif timesampl{i}(j)>=48*3600
timesampl{i}(j)=timesampl{i}(j)-48*3600;
end
end
end
  5 Kommentare
Guillaume
Guillaume am 23 Feb. 2016
Bearbeitet: Guillaume am 23 Feb. 2016
Bear in mind that most of us don't work in the same field as you do, so expressions like 'holter recording HR information' may not mean anything to us.
As input to your function you appear to have two vectors, data that I assume represents some signal, and timestep that obviously represents some time. Yet, early on, you have
time(i) = time(i-1) + data(i);
Is that correct? The data also represents some time? What is its relationship with timestep?
Note that the above could be achieved more simply without a loop as:
time = cumsum([0 data(2:end)]);
It also begs the question, why is data(1) discarded?
Tamilselvam Gunasekaran
Tamilselvam Gunasekaran am 23 Feb. 2016
Sorry about the explanation. I will try to do better in explaining next time time step is calcultated from the data itself. For example if the time is interval between Heart rate is below for 9 consecutive heart beats.
0.337
0.352
0.307
0.302
0.318
0.365
0.405
0.425
And if the starting time is 14:00.000 time will be calculated as
14:00.000+.33700
00:14:00.337
00:14:00.689
00:14:00.996
00:14:01.298
00:14:01.616
00:14:01.981
00:14:02.386
00:14:02.806

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jos (10584)
Jos (10584) am 23 Feb. 2016
% find MEDIAN over that time interval
MyMedian{i}(j)=median(data(strt:n));
  1 Kommentar
Tamilselvam Gunasekaran
Tamilselvam Gunasekaran am 23 Feb. 2016
IT worked for me. It was trying just Median instead of MyMedian. Thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by