Adjust measurement data with different vector lengths using interpolation

12 ビュー (過去 30 日間)
Mepe 2021 年 1 月 26 日
コメント済み: Jan 2021 年 1 月 27 日
I have carried out various series of measurements from which I would like to form arithmetic mean values.
The problem is that one series of measurements has 1200 data points (Vector_1), the second only 1000 (Vector_2) and the third 800 data points (Vector_3).
I tried to adapt this to the largest vector using interpolation:
maxLength = max([length(Vector_1), length(Vector_2), length(Vector_2)]);
xFit = 1:maxLength;
IP_Vector_1 = interp1(1:length(Vector_1), Vector_1, xFit);
IP_Vector_2 = interp1(1:length(Vector_2), Vector_2, xFit);
IP_Vector_3 = interp1(1:length(Vector_3), Vector_3, xFit);
However, this code does not seem to distribute the interpolation evenly, but rather puts it at the end (with NaN). Does anyone have any idea what the problem is or have another suggestion how that could be solved elegantly in Matlab?
Many Thanks!
  2 件のコメント
Mepe 2021 年 1 月 26 日
Sorry for the confusion. The mean values and further operations will be formed later. First of all, it would be important to expand the Vectors.



Jan 2021 年 1 月 26 日
編集済み: Jan 2021 年 1 月 26 日
n1 = length(Vector_1);
n2 = length(Vector_2);
n3 = length(Vector_3);
nMax = max([n1, n2, n3]);
IP_Vector_1 = interp1(1:n1, Vector_1, linspace(1, n1, nMax));
IP_Vector_2 = interp1(1:n2, Vector_2, linspace(1, n2, nMax));
IP_Vector_3 = interp1(1:n3, Vector_3, linspace(1, n3, nMax));
Now the vectors have all nMax steps. Interpolating a vector with x=1:10 at the steps x = 1:20 appends 10 NaNs, because thius is an extrapolation. You need the interval [1, 10] split into nMax steps instead:
1:((10 - 1) / (nMax - 1)):10
% or nicer:
linspace(1, 10, nMax)
Note 1: Normalizing with linear interpolation can destroy important information, if the sampling frequency is low:
v1 = [1, 10, 1];
v2 = [1, 1, 1, 1];
vi1 = interp1(1:n1, v1, linspace(1, n1, nMax)) % [1, 7, 7, 1]
vi2 = interp1(1:n2, v2, linspace(1, n2, nMax)) % [1, 1, 1, 1]
The large peak in v1 is damped. So it is a better idea to use nMax = q * max([n1, n2, n3]) with q = 2 or 5. In a smart program this factor is implemented as variable such that you can compare the results for different scaling factors.
Note 2: If this is time-ciritical, use FEX: ScaleTime, which interpolates faster than INTERP1 or GriddedInterpolant.
  2 件のコメント
Jan 2021 年 1 月 27 日
You are welcome.


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by