| Signal Processing Toolbox | Search  Help Desk |
| upfirdn | Examples See Also |
Upsample, apply an FIR filter, and downsample.
Syntax
yout = upfirdn(xin,h) yout = upfirdn(xin,h,p) yout = upfirdn(xin,h,p,q)
Description
upfirdn performs a cascade of three operations:
.p (zero inserting)
.h
.q (throwing away samples)
upfirdn has been implemented as a MEX-file for maximum speed, so only the outputs actually needed are computed. The FIR filter is usually a lowpass filter, which you must design using another function such as remez or fir1.
NOTE
resample performs an FIR design using firls, followed by rate changing implemented with upfirdn.
yout = upfirdn(xin,h)
returns the output signal yout. If yout is a row or column vector, then it represents one signal; if yout is an array, then each column is a separate output. xin is the input signal. If xin is a row or column vector, then it represents one signal; if xin is an array, then each column is filtered. h is the impulse response of the FIR filter. If h is a row or column vector, then it represents one filter; if h is an array, then each column is a separate impulse response.
yout = upfirdn(xin,h,p)
specifies the upsampling factor p. p is an integer with a default of 1.
yout = upfirdn(xin,h,p,q)
specifies the downsampling factor q. q is an integer with a default of 1.
NOTE
upfirdn performs convolution and rate changing, the yout signals have a different length than xin. The length of y[n] is approximately p/q times the length of x[n].
Remarks
Usually the inputsxin and the filter h are vectors, in which case only one output signal is produced. However, when these arguments are arrays, each column is treated as a separate signal or filter. Valid combinations are
.xin is a vector and h is a vector.
xin with h. The
output signal yout is a row vector if xin is a row; otherwise, it is a column
vector.
.xin is an array and h is a vector.
h with each
column of xin. The resulting yout will be an array with the same number of
columns as xin.
.xin is a vector and h is an array.
h with xin. The resulting yout will be an array with the same number of
columns as h.
.xin is an array and h is an array, both with the same number of columns.
xin and h. The resulting yout is an array with the
same number of columns as xin and h.
Examples
If bothp and q are equal to 1 (that is, there is no rate changing), the result is ordinary convolution of two signals (equivalent to conv):
yy = upfirdn(xx,hh);This example implements a seven-channel filter bank by convolving seven different filters with one input signal, then downsamples by five:
% Assume that hh is an L-by-7 array of filters. yy = upfirdn(xx,hh,1,5);Implement a rate change from 44.1 kHz (CD sampling rate) to 48 kHz (DAT rate), a ratio of 160/147. This requires a lowpass filter with cutoff frequency at
c = 2
/160:
% Design lowpass filter with cutoff at 1/160th of Fs. hh = fir1(300,2/160); % need a very long lowpass filter yy = upfirdn(xx,hh,160,147);In this example, the filter design and resampling are separate steps. Note that
resample would do both steps as one.
Algorithm
upfirdn uses a polyphase interpolation structure. The number of multiply-add operations in the polyphase structure is approximately (LhLx-pLx)/q where Lh and Lx are the lengths of h[n] and x[n], respectively.
A more accurate flops count is computed in the program, but the actual count is still approximate. For long signals x[n], the formula is quite often exact.
Diagnostics
There must be one output argument and at least two input arguments. If either of these conditions are violated,upfirdn gives the appropriate error message:
UPFIRDN needs at least two input arguments. UPFIRDN should have exactly one output argument.If the arrays are sparse,
upfirdn gives the error message
H must be full numeric matrix.When the input signals are in the columns of a matrix and there are multiple filters also in the columns of a matrix, the number of signals and filters must be the same. If they are not,
upfirdn gives the error message
X and H must have the same number of columns, if more than one.The arguments
p and q must be integers. If they are not, upfirdn gives the error message
P and/or Q must be greater than zeroIf the arguments
p and q are not relatively prime, upfirdn gives the warning message
WARNING (upfirdn) p & q have common factor
See Also
conv |
Convolution and polynomial multiplication. |
decimate |
Decrease the sampling rate for a sequence (decimation). |
filter |
Filter data with a recursive (IIR) or nonrecursive (FIR) filter. |
interp |
Increase sampling rate by an integer factor (interpolation). |
intfilt |
Interpolation FIR filter design. |
resample |
Change sampling rate by any rational factor. |
References
[1] Crochiere, R.E., and L.R. Rabiner. Multi-Rate Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 1983. Pgs. 88-91. [2] Crochiere, R.E. "A General Program to Perform Sampling Rate Conversion of Data by Rational Ratios." In Programs for Digital Signal Processing. IEEE Press. New York: John Wiley & Sons, 1979. Pgs. 8.2-1 to 8.2-7.