Resampling

Available Resampling Functions

The toolbox provides a number of functions that resample a signal at a higher or lower rate.

Operation

Function

Apply FIR filter with resampling

upfirdn

Cubic spline interpolation

spline

Decimation

decimate

Interpolation

interp

Other 1-D interpolation

interp1

Resample at new rate

resample

resample Function

The resample function changes the sampling rate for a sequence to any rate that is a ratio of two integers. The basic syntax for resample is

y = resample(x,p,q)

where the function resamples the sequence x at p/q times the original sampling rate. The length of the result y is p/q times the length of x.

One resampling application is the conversion of digitized audio signals from one sampling rate to another, such as from 48 kHz (the digital audio tape standard) to 44.1 kHz (the compact disc standard).

The example file contains a length 4001 vector of speech sampled at 7418 Hz:

clear
load mtlb
whos

Name Size Bytes Class Fs 1x1 8 double array mtlb 4001x1 32008 double array
Grand total is 4002 elements using 32016 bytes Fs Fs = 7418

To play this speech signal on a workstation that can only play sound at 8192 Hz, use the rat function to find integers p and q that yield the correct resampling factor:

[p,q] = rat(8192/Fs,0.0001) 
p =
   127
q =
   115

Since p/q*Fs = 8192.05 Hz, the tolerance of 0.0001 is acceptable; to resample the signal at very close to 8192 Hz:

y = resample(mtlb,p,q);

resample applies a lowpass filter to the input sequence to prevent aliasing during resampling. It designs this filter using the firls function with a Kaiser window. The syntax

resample(x,p,q,l,beta)

controls the filter's length and the beta parameter of the Kaiser window. Alternatively, use the function intfilt to design an interpolation filter b and use it with

resample(x,p,q,b)

decimate and interp Functions

The decimate and interp functions do the same thing as resample with p = 1 and q = 1, respectively. These functions provide different anti-alias filtering options, and they incur a slight signal delay due to filtering. The interp function is significantly less efficient than the resample function with q = 1.

upfirdn Function

The toolbox also contains a function, upfirdn, that applies an FIR filter to an input sequence and outputs the filtered sequence at a sample rate different than its original. See Multirate Filter Bank Implementation.

spline Function

The standard MATLAB® environment contains a function, spline, that works with irregularly spaced data. The MATLAB function interp1 performs interpolation, or table lookup, using various methods including linear and cubic interpolation.

Was this topic helpful?