Resample from a nonuniform time history while keeping the peak and valley values
12 次查看(过去 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);
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!