%% Resample Multichannel Signal
% Generate a five-channel, 100-sample sinusoidal signal. Time increases across the columns and frequency increases down the rows. Plot the signal.

p = 3;
q = 2;

tx = 0:p:300-p;

x = cos(2*pi*tx./(1:5)'/100);

plot(tx,x,'.:')
title('Original')
ylim([-1.5 1.5])

%
% Upsample the sinusoid by 3/2 along its second dimension. Overlay the resampled signal on the plot.

ty = 0:q:300-q;

y = resample(x,p,q,'Dimension',2);

plot(ty,y,'.:')
title('Upsampled')

%
% Reshape the resampled signal so that time runs along a third dimension.

y = permute(y,[1 3 2]);
size(y)

% Downsample the signal back to its original rate and plot it.

z = resample(y,q,p,'Dimension',3);

plot(tx,squeeze(z),'.:')
title('Downsampled')

% Copyright 2020 The MathWorks, Inc.