Signal Processing Toolbox
  Go to function:
    Search    Help Desk 
upfirdn    Examples   See Also

Upsample, apply an FIR filter, and downsample.

Syntax

Description

upfirdn performs a cascade of three operations:

   1.
Upsampling by p (zero inserting)
   2.
FIR filtering with the impulse response given in h
   3.
Downsampling by 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
The function 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
Since 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 inputs xin 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

   1.
xin is a vector and h is a vector.
There is one filter and one signal, so the function convolves xin with h. The output signal yout is a row vector if xin is a row; otherwise, it is a column vector.
   2.
xin is an array and h is a vector.
There is one filter and many signals, so the function convolves h with each column of xin. The resulting yout will be an array with the same number of columns as xin.
   3.
xin is a vector and h is an array.
There are many filters and one signal, so the function convolves each column of h with xin. The resulting yout will be an array with the same number of columns as h.
   4.
xin is an array and h is an array, both with the same number of columns.
There are many filters and many signals, so the function convolves corresponding columns of xin and h. The resulting yout is an array with the same number of columns as xin and h.

Examples

If both p and q are equal to 1 (that is, there is no rate changing), the result is ordinary convolution of two signals (equivalent to conv):

This example implements a seven-channel filter bank by convolving seven different filters with one input signal, then downsamples by five:

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:

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:

If the arrays are sparse, upfirdn gives the error message

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

The arguments p and q must be integers. If they are not, upfirdn gives the error message

If the arguments p and q are not relatively prime, upfirdn gives the warning message

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.



[ Previous | Help Desk | Next ]