resample

Resample a real signal by a rational factor using a polyphase FIR filter.

Syntax

output = resample(x,p,q)

output = resample(x,p,q,h)

Inputs

x
The signal to be resampled. If x is a matrix then each column is resampled.
Type: double
Dimension: vector | matrix
p
The upsample (numerator) factor.
Type: integer
Dimension: scalar
q
The downsample (denominator) factor.
Type: integer
Dimension: scalar
h
The impulse response of the FIR filter (optional).
The default filter is a lowpass filter designed with a Kaiser window. See Comments.
Type: double
Dimension: vector

Outputs

output
The resampled signal.

Example

Resample a curve by a factor of 4/3.

% define signal
fs = 100;
ts = 1/fs;
n = 60;
t = [0:ts:(n-1)*ts];
omega = 2*pi*(fs/4);
x = 8*cos(0.6*omega*t) - 20*sin(0.4*omega*t);

% upsample by a factor of 4/3
p = 4;
q = 3;
ts = (q/p) * ts;
n = (p/q) * n;
tr = [0:ts:(n-1)*ts];
xr = resample(x, p, q);

% plot results
plot(t,x);
hold on;
scatter(t,x);
scatter(tr,xr);
legend('original curve', 'original data', 'resampled data');
Figure 1. resample figure 1


Comments

The default Kaiser window is described in chapter 7 of A. V. Oppenheim, R. W. Schafer and J. R. Buck, Discrete-time signal processing, Signal processing series, Prentice-Hall, 1999.