Cosinor analysis of temperature Excel data

조회 수: 9 (최근 30일)
lamees Arbi
lamees Arbi 2020년 2월 25일
댓글: Star Strider 2020년 3월 3일
Hi there,
I have obtained temperature data over 2 days from participants and it has been saved on an excel spreadsheet with the time and its corresponding temperature at that time. I would like to plot this data using cosinor analysis on matlab but i have never done this. i have attached a sample of this data. there are certain anomalies which i hope wont impact the cosinor analysis. I would really appreciate a code that would help me plot the analysis. it would also be helpful if someone could help/suggest a way to remove the anomalies in the data.
thanks in advance
  댓글 수: 1
darova
darova 2020년 2월 25일
Looks like your data is defective. How do you want to fit cos()?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2020년 2월 25일
One approach:
D = readtable('vital_parameters_15540 (1) copy.xlsx');
x = datenum(D.time) - datenum(D.time(1)); % Date Numbers For Curve Fitting
xd = D.time - D.time(1); % Duration Array
y = D.temperature;
y = y-median(y);
yf = medfilt1(y, 750); % Filter
yu = max(yf);
yl = min(yf);
yr = (yu-yl); % Range of ‘y’
yz = y-yu+(yr/2);
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
zx = find(zci(yf)); % Find zero-crossings
per = 2*mean(diff(zx)); % Estimate period
ym = mean(y); % Estimate offset
fit = @(b,x) b(1).*(sin(2*pi*x./b(2) + 2*pi/b(3))) + b(4); % Function to fit
fcn = @(b) sum((fit(b,x) - y).^2); % Least-Squares cost function
s = fminsearch(fcn, [yr; per; -1; ym]) % Minimise Least-Squares
xp = linspace(min(x),max(x));
figure
plot(xd,yf,'b', xd,fit(s,x), 'r')
grid
text(0.2*mean(xd), 0.6, sprintf('T = %.2f sin(2\\times\\pi\\timest\\times%.2f %.2f) + %.2f', s(1), 1/s(2), 1/s(3), median(D.temperature)))
producing:
This code may not be robust. It works here. The estimated frequency is 1.03 cycles/day with a phase of -1.54 cycles. Note that the time begins at 00:00. Add the beginning time to get the actual time.
I have not done cosinor analysis in decades, so I will leave it to you to plot these in polar coordinates (using the polarplot function) if you want them plotted that way.
  댓글 수: 2
lamees Arbi
lamees Arbi 2020년 3월 3일
That was very useful. Thank you very much. Woulf you be abl o iure out a way to do it or this data set?
Would be much apprciated as im not confiden with matlab
Star Strider
Star Strider 2020년 3월 3일
As always, my pleasure!
There is something seriously wrong with that data set, and it may not be usable. I have to be away for a bit today, so I will give it more consideration when time permits. I cannot make any promises that I can fit it.
Meanwhile, I need to know the format of the ‘time’ column. Is it 'MM/dd/uuuu HH:mm' or 'dd/MM/uuuu HH:mm'? Are the first and second fields month/day or day/month? Both interpretations are possible.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by