How can I resample data to a fixed time grid?

6 views (last 30 days)
Maksim Sorin
Maksim Sorin on 29 Mar 2022
Answered: Chandra on 5 Apr 2022
Hello all,
I am working with datalogs, but I have data that is sampled at different rates and I want to resample everything so that it is on a 0 to "end of datalog" time grid with spacing of .1 seconds each. Creating the fixed time grid is very easy and I have used:
set=[0:.1:height(matrix)];
set=set';
That gives me a 1 column matrix with time starting at 0 and ending at the end of the datalog. Now my question is how can I resample different signals so they all land on that time grid. Some signals get polled at 1000hz while others get polled at 100, 50, etc etc. I need them all to be on one timetable. All of the signals have the same ending time, its just about getting them on a uniform grid.
Thanks!

Answers (1)

Chandra
Chandra on 5 Apr 2022
Hi,
I understood that if a given input data of any length should be adjusted to length of time that provided, irrespective of sample rate and sample length.
here is an example that I took a fixed length of 1000 and variable length of another varaible and the output final variable of given set length of 1000.
f = 1:310; %this is the input data
set = 1000; % This is the length that to be achieved, provide the length that you want to achieve
f_new = interp_1(f,set); % calling a function to achieve interpolation
f_new1 = f_new;
for i=1:5
if(length(f_new1) ==set)
i =6;
else
f_new1 = decp(f_new1,set); % calling a function to adjust the length
end
end
function f_new = interp_1(f,set) % it interpolate according to given data
c = 1;
len = ceil((set)/length(f));
for i = 1:length(f)
f_new(c) = f(i);
c = c+1;
for j = 1:len-1
if(i==length(f))
f1 = f(end);
else
f1 = f(i+1);
end
f_new(c) = j*((f1-f(i))/len)+f(i);
c = c+1;
end
j = 1;
end
end
function f_new1 = decp(f_new,set) % it decimate to required length
len1 = length(f_new);
data = len1-(set);
data1 = ceil(len1/data);
data2 = data1;
c1 = 1;
f_new1 = zeros(1,set);
for i = 1:length(f_new)
if i==data1
data1 = data1+data2;
else
f_new1(c1) = f_new(i);
c1 = c1+1;
end
end
end
generally the decp function took 2 iteration to get required result, this code helps to change the length of data to any size,
here the data is interpolated and the decimated because the ratio is nonlinear, in order to make it linear we done interpolation and decimation
refer interpolation and decimation of matlab

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by