Resampling two signals to the same sampling time and length

Hi guys !
For further system analysis I need to adapt two signals to the same length and sampling time. The signals are measured outputs of the system and the underlying input signals. They are sampled as follows:
t_input = 5ms
t_output = 2ms
Consequently, the signal vectors are of different lengths, too. My goal is to resample the signals to the output sampling time of t_output = 2ms and to make them equal-length. As an interpolation I want to use a linear interpolation. I have tried different methods and wrote functions to obtain the results, but have not been successful for days now. I used interp1 to interpolate between the input signal values, but it either didn't work or I haven't been able to make it work. I now seek help from you guys to fight this task! I do not want to use the matlab resampling function!
I have attached the input signal sine_input and the output signal sine_output. They consist of two columns, the first is the time stamp vector, the second column contains the measured output values or given input values, respectively.
I hope you guys can help !!!
Thank YOU !

6 Comments

Why you don't like resample function ?
interp1 should work fine, but you didn't show how you used it so it's hard to say much more.
My attempt at interp1:
function [ti,yi,tsi,ysfi] = resampleData(refData, measData, doPlot)
t = refData(:,1); t = t - t(1);
y = refData(:,2);
ts = measData(:,1); ts = ts - ts(1);
ys = measData(:,2);
ti = t(1) : round(mean(diff(ts))*1000)/1000 : min([t(end),ts(end)]);
yi = interp1(t, y, ti,'linear',0);
% Additional filtering of the signal using butter_filt
ysf = butter_filt(ts,ys,50,4);
ysfi = interp1(ts,ysf,ti,'linear',0);
tsi = ti;
end
What are in your .mat files?
Is the first column time, or something else? When I plotted them, with the second columns (signal?) as a function of the first columns (time?), the first columns were not even close to overlapping. They appeared to have nothing at all in common.
The first column is the time stamp of the measurement equipment. It has effectively no other meaning than to specify the time instant at which the output was measured. So you wont be able to plot the signal over time.
‘So you wont be able to plot the signal over time.
Then there is nothing to do.
I will delete the files.

Sign in to comment.

 Accepted Answer

Interp1 should work fine here
if size_input is the number of samples of your input, and size_output is the number of samples of your output, then simply.
input_resampled = interp1(linspace(0,1,size_input), input, (linspace(0,1,size_output));

2 Comments

Thank you very much ! It works just the way I want it to !!!!!!!!
I just want to know why you use linspace ? Wouldn't it be enough to use length(input) ? :)
When interp1 is called with three arguments, they each mean:
Argument 1: Vector in interval of the input with length of the input
Argument 2: The input
Argument 3: Vector in interval of the output with length of the output
Since we want the output to span the same interval as the output, but with different length, we use linspace to decide the length, but keep the interval the same.You don't actually need to use 0 and 1 as long as you're consistent, you could use any two numbers.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!