Stretch downsampled data to fit on same x axis

I have an array1 sampled at 2Khz for 500 seconds.
I want to visualize the hilbert transform of the data at a lower sampling rate (i.e. smoother trend)
To accomplish this I used array2 = downsample(array1, 4) then performed the hilbert transform.
As a result, array2 is shorter than array1 even though they represent the same amount of time.
How can I now "stretch" array2 back to the length of array1 so that I can view them on a plot simultaneously with the same time axis?
Fs = 2000
t = 500
>> ar1 = 1:1:Fs*t;
>> ar2 = downsample(x,4);
>> length(ar1)
ans =
1000000
>> length(ar2)
ans =
250000
>> ar2 = hilbert(ar2);
% Now how to plot ar1 and transformed ar2 on same time x axis?
Two ideas I had were: repelem, which would just make any given array2 value repeat x number of times, or upsample(), but this introduces 0's into the array. I'd rather have a smooth line if possible. Thank you!

 Accepted Answer

DGM
DGM on 3 Feb 2022
Edited: DGM on 3 Feb 2022
There are probably tools to do this in SPT, but I don't see why interpolation won't work.
Fs = 2000
t = 500
ar1 = 1:1:Fs*t;
ar2 = downsample(ar1,4);
nc = numel(ar2);
nf = numel(ar1);
ar2f = interp1(linspace(1,nf-3,nc),ar2,1:nf);
numel(ar2f) % now ar2f has the same length as ar1

More Answers (0)

Products

Release

R2021b

Asked:

on 3 Feb 2022

Edited:

DGM
on 3 Feb 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!