Resampling Data using Interp1

조회 수: 42 (최근 30일)
Lucianne Morin
Lucianne Morin 2020년 6월 29일
댓글: Star Strider 2020년 7월 1일
Hello!
This may be a fairly obvious answer, but I'm trying to resample some data down to 100 Hz using interp1. I load my data, and then extract the first column (which is the time series) to use in my for loop. However, I get the error "Interpolation requires at least two sample points in each dimension." I tried adjusting the code to call for a(i+1) to see if maybe I needed to start later, but I got the same error. The data itself is part of my thesis so I'm not sure if I can attach it, but I've copy and pasted my code below.
Thank you in advance for any help!
load('BNI_processed.mat')
a = Force_arr;
time_matrix =(a(1:end,1)).';
for i = 1:length(time_matrix)-2
aa = length(time_matrix(i):time_matrix(i+1));
p = 61;
Force(:,i)=interp1(a(i,2),1:aa/p:aa, 'spline');
end
  댓글 수: 1
Image Analyst
Image Analyst 2020년 6월 30일
Youi forgot to attach the mat file. We'll check back tomorrow.

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

채택된 답변

Star Strider
Star Strider 2020년 6월 30일
You are doing signal processing. For that, use the resample function. It will do the interpolation, and will also use an anti-aliasing filter to remove unwanted artifacts. I am not certain what your signal is or what you want to do with it, so I cannot provide a link to the most appropriate section of the resample documentation for that.
  댓글 수: 2
Lucianne Morin
Lucianne Morin 2020년 7월 1일
The reason why I'm not using the resample function is because my data is derived from the activation of pressure sensors, so the sampling frequency isn't consistant across the time series (it's 128.5935...). I spent some time trying to set the two integers to get it, but I need to resample to 100 Hz exactly and it wasn't working out. I'm attaching my code if that helps, I did find a work around for the interp1 but there is aliasing in the data right now.
Thanks for your help.
Star Strider
Star Strider 2020년 7월 1일
I was hoping for ‘BNI_processed.mat’. Lacking it, the resample function can do exactly what you wantpreviously, since I have done this previously.
From the documentation (there is no specific link to this line):
  • y = resample(x,tx,fs) uses a polyphase antialiasing filter to resample the signal at the uniform sample rate specified in fs.
Referring to your code, this would probably be:
[force_array, p_new] = resample(a(:,2:end), p, 100);
[shoe_array, q_new] = resample(b(:,2:end), q, 100);
I cannot determine for certain that will work because I do not have ‘BNI_processed.mat’ to work with and check. I am going only by your interp1 calls.
Without ‘BNI_processed.mat’, my only option is to post this as UNTESTED CODE. It should do what you want.
.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 7월 1일
편집: Walter Roberson 2020년 7월 1일
load('BNI_processed.mat')
input_forces = Force_arr(:,2);
time_matrix = Force_arr(:,1);
Fs = 100;
last_time = ceil(time_matrix(end) / Fs) * Fs; %round UP
time_to_interp = 0 : 1/Fs : last_time;
Force = [time_to_interp; interp1(time_matrix, input_forces, time_to_interp)] .;

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by