the resample function throws errors for only a few, but not all, the rows of a large timetable

10 views (last 30 days)
Ref.: resample function from Matlab release 2024a Prerelease Update 3
I can't figure out why the resample function gives an error only for a few particular rows in a large timetable (stored in the variable T).
The script I am using is copied below, and I have attached the workspace variables, including the data I am using.
T is a timetable with heartbeat measurements. Each minute has a different number of measurements (for example: for the timestamp 17/02/2023 23:21 there are 66 heartbeat measurements; for 18/02/2023 05:02 there are 88 measurements; and so on). In addition, there are gaps in the time series. We don't want to fill the gaps; the goal is only to resample the data for the minute-resolved timestamps, so there are always 60 measurements per minute.
The script below resamples the data corresponding to each individual minute. But it works for most, but not all the data. For particular portions of the data, the resample function throws an error. The indexes to these data portions, as well as the error messages have been saved in the variable "Errorlist".
Furthermore, if, when there is an error, the sampling rate is reduced by 1, the function "resample" processes the data. I used the try-catch lines as "brute force" to resample most of the timetable, but can't figure out why the function resample fails for some particular chunks of the data.
On a previous post, a limit of 2^31 for RateOld*RateNew is mentioned, but I am not sure this is the same case.
Any "enlightening" will be very much appreciated. Thanks a million for your help in advance!
U=timetable;
Errorlist=table(); %%% Stores the indexes of the data that trigger errors and the error messages
for i=1:1:height(iKQ)
p=iKP(i);
q=iKQ(i);
RateOld=q-p+1;
RateNew=60;
Sample=timetable(T.Time(p:q),T.HeartRate(p:q));
try
Resample=resample(Sample,RateNew,RateOld,15,150);
catch ME
Errorline=table(i,p,q,string(getReport(ME)));
Errorlist=[Errorlist;Errorline];
p=p+1;
Resample=resample(Sample,RateNew,(RateOld-1),15,150);
end
U=[U; Resample]; % U is the resampled data at 1 Hz
end

Answers (1)

SAI SRUJAN
SAI SRUJAN on 16 Mar 2024
Hi Ana,
I understand that you are facing an issue with the function 'resample' in MATLAB.
The encountered errors with the resample function on specific data segments likely stem from a limitation related to the maximum allowable product of the original and new sampling rates ('RateOld * RateNew'). This suggests a threshold beyond which the function cannot process data effectively.
Observations indicate that slightly reducing the sampling rate by 1 allows for error-free resampling. This implies that the issue is tied to particular combinations of sampling rates for those segments.
Make sure the numbers for 'RateOld' and 'RateNew' in the parts of the data that are causing problems are correct. These numbers need to be in the right range for the resampling function to work. If they're not, try changing these rates to see if it fixes the errors.
It might help to use a different method to resample your data. MATLAB has other tools like 'interp1' that you can use to resample your data.
I hope this helps!
  1 Comment
Ana Egatz-Gomez
Ana Egatz-Gomez on 18 Mar 2024
Thank you Sai. I agree with you. I have decided not to use 'resample' after all, because I also noted that it introduces noise. In the picture I have attached, the noise introduced by 'resample' is the downward peaks at the new desired sampling frequency.

Sign in to comment.

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!