
function xext=insertsamples(x,INS,type);

% function XEXT=insertsamples(X,INSERT,TYPE); % FILL IN SAMPLES
%
% It fills in INSERT number of new samples between the samples
% given in the input vector X. The samples are linearly interpolated
% between the original samples of X. The first and last samples of
% the output XEXT are the same as the first and last samples of X.
%
% If the last argument is given TYPE='log', then the inserted samples
% are logarithmically interpolated.
%
% Example: 
%   insertsamples([1 3 4],1) gives
%   [1 2 3 3.5 4]
%
% C. Balazs Bank, 2016.

if nargin<3,
    type='lin';
end;

S=size(x);
if (S(1)>1)&&(S(2)>1),
    error('Error: Input must be a vector.');
end;

x=x(:).'; % make a row vector



if type=='log', % if the values must be on a logarithmic scale
    x=log(x);
end;

xext=[];
K=length(x);
for k=1:K-1,
    newpart=(x(k+1)-x(k))*[0:INS]/(INS+1)+x(k);
    xext=[xext newpart];
end;
xext=[xext x(end)];

if S(1)>1, % if input was a column vector
    xext=xext.';
end;

if type=='log', % if the values must be on a logarithmic scale
    xext=exp(xext);
end;

    