How to interpolate/resample an irregular dataset into 1 step spacing?
6 views (last 30 days)
Show older comments
Becky Hopkins
on 24 Nov 2022
Commented: Mathieu NOE
on 25 Nov 2022
Hi all!
I am trying to resample my irregular dataset (on age) to regular 1 step intervals. The data was previously resampled from depth to age using tie points, but I have no tie points to the 1 step intervals. I'm trying to interpolate the data 0:1:3000.
I have tried 'resample' and 'interp1' but think I must be doing something wrong as I get outputs not on regular 0:1:3000 steps, or error messages.
interval_resampled = resample(dataset_resample_issue(:,1);, dataset_resample_issue(:,2);, ((0:1:3000).'));
Error using resample
Expected input number 3, Fs, to be a scalar.
Error in resample>validateFs (line 842)
validateattributes(fs, {'numeric'},{'real','finite','scalar', ...
Error in resample>nonUniformResample (line 285)
validateFs(fs);
Error in resample (line 235)
nonUniformResample(isDimValSet,Dim, m, method1, dimIn, xIn, ...
Any advice would be much appreciated! Thank you!
Becky
1 Comment
Star Strider
on 24 Nov 2022
What do you want to do?
The current ranges for the variables are:
LD = load(websave('dataset_resample_issue','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1205953/dataset_resample_issue.mat'));
dataset = LD.dataset
format longg
MinMax = [min(dataset); max(dataset)]
.
Accepted Answer
Mathieu NOE
on 24 Nov 2022
hello Becky
try this
the second case means you ask interp1 to do extrapolation, as your original x data do not covers the entire 0 to 3000 range
use at your own risks !
load('dataset_resample_issue.mat')
x = dataset(:,1);
y = dataset(:,2);
% remove first NaNs in x array
idx = ~isnan(x);
x = x(idx);
y = y(idx);
%% option 1 : no extrapolation (xi will go from 11 to 2903 by step = 1 )
xi = ceil(x(1)):1:floor(x(end)); % make sure the new x axis correspond to the min / max range of x (after NaN removal)
yi = interp1(x,y,xi,'linear');
figure(1),plot(x,y,'b*',xi,yi,'r-');
legend('input data', 'resampled data');
%% option 2 : with extrapolation (xi will go from 0 to 3000 by step = 1 )
xi = 0:1:3000; % make sure the new x axis correspond to the min / max range of x (after NaN removal)
yi = interp1(x,y,xi,'linear','extrap');
figure(2),plot(x,y,'b*',xi,yi,'r-');
legend('input data', 'resampled data');
2 Comments
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!