function [newX,newY1,newY2] = interpExtrap(X1,Y1,X2,Y2)
% Function that takes in two waveform data represented by [X1,Y1] and
% [X2,Y2] respectively and returns resample waveforms that have the
% same time points represented as [newX newY1] and [newX newY2]
% respectively.

% X1 and X2 are the time vector of two waveforms which are combined to give
% one vector of time points that have time stamps from both waveform.

% Copyright 2020, The MathWorks, Inc.
if(length(X1) ~= length(Y1))
    error(message('msblks:msblksMessages:SignalDataMismatch','[X1 Y1]'));
    %error('Length of time vector should be equal to the length of signal value vector for first signal represented by [X1 Y1]');
end

if(length(X2) ~= length(Y2))
    error(message('msblks:msblksMessages:SignalDataMismatch','[X2 Y2]'));
    %error('Length of time vector should be equal to the length of signal value vector for second signal represented by [X2 Y2]');
end

if(iscolumn(X1))
    X1=X1';
    Y1=Y1';
end

if(iscolumn(X2))
    X2=X2';
    Y2=Y2';
end
newX=unique([X1,X2]);

% Using the new common time vector, newX, to get the Y points for both waveform
% using interp1 command
newY1=interp1(X1,Y1,newX,'linear','extrap');
newY2=interp1(X2,Y2,newX,'linear','extrap');