|Signal Processing Toolbox||Search Help Desk|
|resample||Examples See Also|
Change sampling rate by any rational factor.
y = resample(x,p,q) y = resample(x,p,q,n) y = resample(x,p,q,n,beta) y = resample(x,p,q,b) [y,b] = resample(x,p,q)
y = resample(x,p,q)resamples the sequence in vector
p/qtimes the original sampling rate, using a polyphase filter implementation. The length of
yis equal to
qmust be positive integers. If
xis a matrix,
resampleworks down the columns of
resampleapplies an anti-aliasing (lowpass) FIR filter to
xduring the resampling process. It designs the filter using
firlswith a Kaiser window.
y = resample(x,p,q,n)uses
nterms on either side of the current sample,
x(k), to perform the resampling. The length of the FIR filter
resampleuses is proportional to
n; larger values of n provide better accuracy at the expense of more computation time. The default for
nis 10. If you let
n = 0, resample performs a nearest-neighbor interpolation:
y(k) = x(round((k-1)*q/p)+1)where
y(k)= 0 if the index to
xis greater than
y = resample(x,p,q,n,beta)uses beta as the design parameter for the Kaiser window that
resampleemploys in designing the lowpass filter. The default for be
y = resample(x,p,q,b)filters
b, a vector of filter coefficients.
[y,b] = resample(x,p,q)returns the vector
b, which contains the coefficients of the filter applied to
xduring the resampling process.
ExamplesResample a simple linear sequence at 3/2 the original rate:
Fs1 = 10; % original sampling frequency in Hz t1 = 0:1/Fs1:1; % time vector x = t1; % define a linear sequence y = resample(x,3,2); % now resample it t2 = (0:(length(y)-1))Notice that the last few points of the output
*Fs1); % new time vector plot(t
1,x,'*',t2,y,'o',-0.5:0.01:1.5,-0.5:0.01:1.5,':') legend('original','resampled'); xlabel('Time')
yare inaccurate. In its filtering process,
resampleassumes the samples at times before and after the given samples in
xare equal to zero. Thus large deviations from zero at the end points of the sequence
xcan cause inaccuracies in
yat its end points. The following two plots illustrate this side effect of
x = [1:10 9:-1:1]; y = resample(x,3,2); subplot(2,1,1); plot(1:19,x,'
*2/3 + 1,y,'o'); title('Edge Effects Not Noticeable'); legend('original','resampled'); x = [10:-1:1 2:10]; y = resample(x,3,2); subplot(2,1,2); plot(1:19,x,'
*2/3 + 1,y,'o') title('Edge Effects Very Noticeable'); legend('original','resampled');
qare not positive integers,
resamplegives the appropriate error message:
P must be a positive integer. Q must be a positive integer.If
xis not a vector,
resamplegives the following error message:
Input X must be a vector.
||Decrease the sampling rate for a sequence (decimation).
||Least square linear-phase FIR filter design.
||Increase sampling rate by an integer factor (interpolation).
||One-dimensional data interpolation (table lookup) (see the online MATLAB Function Reference).
||Interpolation FIR filter design.
||Cubic spline interpolation (see the online MATLAB Function Reference).
||Upsample, apply an FIR filter, and downsample.