Resample from a nonuniform time history while keeping the peak and valley values
조회 수: 11 (최근 30일)
이전 댓글 표시
Hi,
I have a time series with a nonuniform time vector. The attached spread sheet contains two columns. The first column (Time in seconds) ranges from 0.04 to 901 seconds. The second column is RPM. I would like to resample from this time history unifromly with time=0:0.25:900.
I used different resampling techniques using MATLAB documentation. In all of them, I lose the peak and valley values. Peak and valley values are important to me as they define the maximum and minimum wind speed.
How can I resample from this time history on a uniform time vector while I keep the peak and valley values? Is there a way to force the algorithm to choose the extremum values when the different between time values are small?
Thank you in advance :)
댓글 수: 3
채택된 답변
Image Analyst
2020년 12월 22일
Did you try interp1() with the 'nearest' option. Since your peak may be between new time sample points, you will lose the peaks unless you use the 'nearest' option:
fprintf('Beginning to run %s.m ...\n', mfilename);
data = readmatrix('Mtlb.xlsx');
t = data(:, 1);
y = data(:, 2);
% Plot original data.
subplot(1, 2, 1);
plot(t, y, 'b-');
grid on;
title('Original Data', 'FontSize', 18);
xlabel('t', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
xlim([0, max(t)]);
newt = 0:0.25:900;
% Imterpolate without losing peaks.
newy = interp1(t, y, newt, 'nearest');
% Plot the interpolated data.
subplot(1, 2, 2);
plot(newt, newy, 'b-');
grid on;
title('Interpolated Data', 'FontSize', 18);
xlabel('new t', 'FontSize', 18);
ylabel('new y', 'FontSize', 18);
xlim([0, max(t)]);
fprintf('Done running %s.m ...\n', mfilename);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/468825/image.png)
댓글 수: 0
추가 답변 (1개)
the cyclist
2020년 12월 22일
편집: the cyclist
2020년 12월 22일
There is almost certainly not a built-in function that does this resampling in the exact way you want. Instead, you need to think about properties of the original data you need to retain, and what you don't. So, for example, if t and rpm are your original data, then you can do a simple interpolation
t0 = 0 : 0.25 : 900;
rpm0 = interp1(t,rpm,t0);
to get rpm values at evenly spaced time points.
Then, you could just manually replace the interpolated highest and lowest values of the interpolated rpm with the known high and low.
Is that sensible? If not, you need to provide more detail about what aspects of the resampling are critical, so that we can help guide you to a solution. (It might also help if you upload the code you have tried, and explain why the result is unsatisfactory in a little more detail.)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!