MATLAB Answers

Ryan
0

How to identify corners of data plotted to estimate data between corners

Asked by Ryan
on 28 Jul 2019
Latest activity Edited by David Wilson on 28 Jul 2019
I have oil pressure data as shown in the plot attached. The data is 10 Hz (speed data points are collected) but the signal is only updated at 1Hz. This leads to data that looks like a series of steps. I know that when there is a step change in the data, that instantaneous data point is valid. The following 9 data points are frozen at the last value, but in reality the pressure is continuing to increase.
I would like to estimate the pressure data between the corners of these steps. I could use diff to identify the data points where the change in value occurs, then interpolate 9 data points between the corners, but that seems like a long way to go. A moving average will smooth the steps out, but it bisects through the middle of the steps. The desired output data is also shown in the below image.

  0 Comments

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by David Wilson on 28 Jul 2019
Edited by David Wilson on 28 Jul 2019
 Accepted Answer

How about using interp1 with the 'pchip' option? You did speculate the interpolation is overly complex, but then again it is only one line in Matlab.
First I generate some (fake) data similar to what you have shown.
y = @(x) 320*(1+tanh(x-5));
x = linspace(0,8)';
Ts = 1; % [s]
xi = [0:Ts:8]';
[xs,ys] = stairs(xi, y(xi))
plot(x,y(x), xs, ys, xi, y(xi), 'rs')
Now the ZOH sample & held data is (xi, y(xi)). Using only this data, we reconstruct the higher density data with interp1.
Ts2 = Ts/10;
xi2 = [0:Ts2:8]';
yq = interp1(xi, y(xi), xi2, 'pchip');
plot(xi, y(xi), 'rs', xi2, yq, 'b-')
I use the pchip option to avoid "wobbles" in the interpolation.
test.png

  0 Comments

Sign in to comment.