MATLAB: I am trying to downscale some hourly data to 5 min data using the resample command, but I am getting negative values in the output

downscalinginterpolaterainfallresample

There seems to be a few interpolate commands out there – interp1, resample – I used resample but it's not working properly. For one year I start with 8760 rows of rainfall data and should end up with 105120 rows – which I do…but there are negative values in my new table (which is obviously wrong?!)
This is the code:
clear all
filename=\MatLab\HourlyRainfallData_533.xlsx';
sheet='2006';
xlRange='A1:A8760';
rain=xlsread(filename,sheet,xlRange);
p = 12;
q = 1;
mins=resample(rain,p,q);

Best Answer

"resample applies an antialiasing FIR lowpass filter to x and compensates for the delay introduced by the filter."
So you are getting overshoot on the filtering.
newx = linspace(1, length(rain), 12*length(rain));
mins = interp1(1:length(rain), rain, newx, 'linear');
When people think about resampling something N times, they often think of it as something similar to taking N copies of each entry, except interpolating instead of straight copies. However, this mental model implies taking N copies of the final value, and then having nothing to interpolate it against.
The code I use above says "Okay, there has to be 105120 points including the first and the last, so we need to interpolate at 105118 interior points spaced 8759/105119 apart . This works out just fine mathematically, but it isn't what people would tend to expect.
Related Question