Interpolation of two-week temperature data into hourly measurements in Matlab

I have a dataset of annual temperature measurements recorded every two weeks. The data looks something like this:

t = 1:14:365; % GENERATE DATA y = 1 + (30-1).*rand(1,length(t)); y1 = 20*sin(2*pi*t/max(t)); % Annual variation °C y1(y1<0) = []; tt = 365/14; time = 1:tt:365; plot(time,y1,'-o'); 

where it clearly follows the annual temperature cycle.

From this, I wonder if it is possible to add a sine function (which will represent the daily temperature range) to the data? For example, from two-week data, if we interpolated the series to have 8760 measurements, i.e. hourly measurements, so that the series was believable, it would have to be characterized by a daily temperature cycle in addition to the annual temperature cycle. In addition, the daily temperature cycle would have to be a function of temperature measurements at that time, that is, it would have been more summer than winter. Therefore, it might be better to use linear interpolation first to get the data in the form of hourly intervals, and then add a sinusoidal function. Is there any way to write this in a script? or does anyone have an opinion on how to achieve this exactly?

+4
source share
2 answers

You can first interpolate your data (up to 1 hour) using something like

 x = 1:inv(24):365; T_interp = interp1(t,y1,x,'spline'); 

Check out the Matlab documentation for interp1 (example 2)

and then add a sine to it. The next sine of period 1 (24 hours) with amplitude A with a minimum of 3 hours.

 T_diurn = -A*sin(2*pi*x+(3/24)*2*pi); 

Then

 T_total = T_diurn + T_interp; 
+5
source

First: do you know that beautiful stories are the most misleading things? Interpolating data collected every 14 days to look like data collected every hour is considered at least bad practice in most circles ...

Having said that, I would use spline for interpolation - they are much more flexible when it comes to switching from a two-week and hourly to any arbitrary other combination, plus the annual temperature change will be much smoother,

Here's how:

 % Create spline through data pp = spline(time, y1); % define diurnal variation (this one is minimal at 4 AM) T_diurn = @(t) -A*cos(2*pi*(t-(4/24))); % plot example t = 150 : 1/24 : 250; plot( t, ppval(pp,t)+T_diurn(t) , 'b') 
0
source

Source: https://habr.com/ru/post/1443168/


All Articles