How to use linear interpolation to resample taken data?

조회 수: 7 (최근 30일)
Petch Anuwutthinawin
Petch Anuwutthinawin 2021년 7월 9일
편집: Petch Anuwutthinawin 2021년 7월 10일
I am given a .csv file with three columns. The second column is dependent upon the first and third columns. The first column is chanel used to measure, second is voltage, third is time when the data was taken. I need to use linear interpolation to resample the voltage in the second column for each sensor with respect to the sensor and time. Each sensor took 17seconds of data in 1/120 second increments. I have written code to do a double variable interpolation for the data to 'synchronise' the data. It does not work. Do I have to somehow seperate each sensor into its own command first?
A=csvread('forcetest.csv')
Chanel=A(:,1)';
Voltage=A(:,2)';
Time=A(:,3)';
T=linspace(1,17,2040);
C=linspace(0,3,2040);
[Ti,Chi]=meshgrid(T,C);
interp2(Time,Chanel,Voltage,Ti,Chi,'linear')

답변 (1개)

Walter Roberson
Walter Roberson 2021년 7월 9일
Yes, you need to separate by channel. You can do that by using
A3d = reshape(A, 3, [], size(A,2));
Voltages = permute(A3d(:,2,:), [1 3 2]);
Times = permute(A3d(:,3,:), [1 3 2]);
Voltages and Times are now both 2D arrays in which the 3 columns correspond to the three channels.
  댓글 수: 1
Petch Anuwutthinawin
Petch Anuwutthinawin 2021년 7월 10일
편집: Petch Anuwutthinawin 2021년 7월 10일
How does this code fit into the main code? I thought something like this would work:
A=csvread('forcetest.csv');
A3d = reshape(A, 4, [], size(A,2)); %total time of recording?
Voltages = permute(A3d(:,2,:), [1 3 2]); %voltages seperated by column by chanel
Times = permute(A3d(:,3,:), [1 3 2]); %time seperated by chanel by column.
[Ti,Chi]=meshgrid(Times,A3d);
interp2(Times,Voltages,Ti,Chi,'linear');
%it dosent work?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by