2.161 Signal Processing: Continuous and Discrete: Mit Opencourseware

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

MIT OpenCourseWare

http://ocw.mit.edu

2.161 Signal Processing: Continuous and Discrete


Fall 2008

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
MASSACHUSETTS INSTITUTE OF TECHNOLOGY

DEPARTMENT OF MECHANICAL ENGINEERING


2.161 Signal Processing – Continuous and Discrete

Data Resampling: Interpolation (Up-sampling) and Decimation


(Down-sampling) 1

1 Up-Sampling (Interpolation) by an Integer Factor


Consider a data set {fn } of length N , where fn = f (nΔT ), n = 0 . . . N − 1 and ΔT is the sampling
interval. The task is to resample the data at a higher rate so as to create a new data set {fˆn }.
of length KN , representing samples of the same continuous waveform f (t), sampled at intervals
ΔT /K. Figure 1(a) shows a cosinusoidal data set with N = 8 samples, and Fig. 1(b) shows the

1 1
(a) original data set (b) interpolated data set
(8 samples) (32 samples)

0.5 0.5

0 0

−0.5 −0.5

−1 −1
2 4 6 8 10 20 30

Figure 1: (a) a data set with N = 8 samples, and (b) an interpolated data set (K = 4) derived
from (a).

same data set interpolated by a factor K = 4.

1.1 Frequency Domain Method


This method is useful for a finite-sized data record. Consider the DFTs {Fm } and {F̂m } of a pair
of sample sets {fn } and {fˆn }, both recorded from f (t) from 0 ≤ t < T , but with sampling intervals
ΔT and ΔT /K respectively. Let N and KN be the corresponding sample sizes. It is assumed that
ΔT has been chosen to satisfy the Nyquist criterion:

1
D. Rowell August 18, 2008

1
• Let F (jΩ) = F {f (t)} be the Fourier transform of f (t), and let f (t) be sampled at intervals
ΔT to produce f ∗ (t). Then

∞ � � ��

∗ 1 � 2πn
F (jΩ) = F j Ω− (1)
ΔT n=0 ΔT

is periodic with period 2π/ΔT , and consists of scaled and shifted replicas of F (jΩ). Let the
total sampling interval be T to produce N = T /ΔT samples.
• If the same waveform f (t) is sampled at intervals ΔT /K to produce fˆ∗ (t) the period of its
Fourier transform F̂ ∗ (jΩ) is 2πK/ΔT and

∞ � � ��

ˆ ∗ K � 2πKn
F (jΩ) = F j Ω− (2)
ΔT n=0 ΔT

which differs only by a scale factor, and an increase in the period. Let the total sampling
period be T as above, to generate KN samples.
• We consider the DFTs to be sampled representations of a single period of F ∗ (jΩ) and F̂ ∗ (jΩ).
The equivalent line spacing in the DFT depents only on the total duration of the sample set
T , and is ΔΩ = 2π/T in each case:
� � ��
∗2πm
Fm = F j , m = 0, 1, . . . N − 1
T
� � ��
2πm
F̂m = F̂ ∗ j , m = 0, 1, . . . KN − 1.
T

� �
From Eqs. (1) and (2) the two DFTs {Fm } and Fˆm are related:



⎨ KFm m = 0, 1, . . . , N/2 − 1
F̂m = 0 m = N/2, . . . , N K − N/2 − 1

⎩ KF
m−(K−1)N m = N K − N/2, . . . , KN − 1

• The effect of increasing N (or decreasing ΔT ) in the sample set, while maintaining T = N ΔT
constant, is to increase the length of the DFT by raising the effective Nyquist frequency ΩN .
π Nπ
ΩN = =
ΔT T
Figure 2 demonstrates these effects by schematically, by comparing the DFT of (a) a data set
of length N derived by sampling at intervals ΔT , and (b) a data set of length 2N resulting from
sampling at intervals ΔT /2. The low frequency region of both spectra are similar, except for a
scale factor, and the primary difference lies in the “high frequency” region, centered around the
Nyquist frequency, in which all data points are zero.
The above leads to an algorithm for the interpolation of additional points into a data set, by a
constant factor K:
1. Take the DFT of the original data set to create {Fm } of length N .
2. Insert (K − 1)N zeros into the center of the DFT to create a length KN array.
3. Take the IDFT of the expanded array, and scale the sequence by a factor K.
Appendix A describes a simple MATLAB function to interpolate a real data set using this method.

F
m
N u m b e r o f s a m p le s : N
S a m p lin g in te r v a l: D T

N y q u is t fr e q u e n c y

-N /2 0 N /2 N 3 N /2 2 N m
(a )
F
m
N u m b e r o f s a m p le s : 2 N
S a m p lin g in te r v a l: D T /2

N y q u is t fr e q u e n c y

0 N 2 N m

(b )

Figure 2: Envelopes of (a) the DFT of a sample set with N samples, and (b) the DFT of the same
waveform with 2N samples.

1.2 A Time-Domain Method


We now examine an interpolation scheme that may implemented in real-time using time domain
processing alone. As before, assume that the process f (t) is sampled at intervals ΔT , generating
a sequence {fn } = {f (nΔT )}. Now assume that K − 1 zeros are inserted between the samples to
form a sequence {fˆk } at intervals ΔT /K. This is illustrated in Fig. 3, where a data record with
N = 8 samples has been expanded by a factor K = 3 to form a new data record of length N = 24
formed by inserting two zero samples between each of the original data points.
We now examine the effect of inserting K − 1 samples with amplitude 0 after each sample. The
DFT of the original data set is
N
� −1
2πmn
Fm = fn e−j N , m = 0...N − 1
n=0

and for the extended data set {fˆn }, n = 0 . . . KN − 1


KN
�−1 2πmn
F̂m = fˆn e−j KN , m = 0 . . . KN − 1
n=0

However, only the original N samples contribute to the sum, so that we can write
N
� −1
2πmk
F̂m = fˆKk e−j N
k=0
= Fm , m = 0 . . . KN − 1

since fˆKk = fk . We note that {Fm } is periodic with period N , and {F̂m } is periodic with period
KN , so that {F̂m } will contain K repetitions of {Fm }. This is illustrated in Fig. 4, which shows

f 3
n

0 n
0 1 2 3 4 5 6 7
(a) Initial data set, N=8
f 3
n
2

0 n
0 5 10 15 20
(b) Data set with two samples interpolated between samples, N=24

Figure 3: (a) A sample set with N = 8 samples, and (b) the same waveform with 2 zero amplitude
samples interpolated between each of the original samples.

F 10
m
8

2
m
0
0 1 2 3 4 5 6 7
(a) DFT of Initial data set, N=8
^
F 10
m
8

2
m
0
0 5 10 15 20
(b) DFT of data set with two samples interpolated between samples, N=24

Figure 4: (a) DFTs of the sample sets shown in Fig. 3. In (a) the DFT {Fm } is periodic with
period 8, and in (b) the DFT {F̂m } is periodic with period 24.

the magnitude of the DFTs of the two waveforms in Fig. 3. The effect of inserting the K − 1 zeros
between the original samples has been to generate a waveform with an equivalent sampling interval
of ΔT /K s, and a Nyquist frequency of Kπ/ΔT rad/s. The line resolution is unchanged, and the
original DFT {Fm } is replicated K times within the frequency span of 2Kπ/ΔT rad/s.
The fully interpolated waveform may be reconstructed by elimination of the replications of the
original spectral components. While this might be done in the frequency domain, the most common
method is to low-pass filter the padded data sequence to retain only the base-band portion of the
spectrum as shown in Fig. 5.
^
F m lo w - p a s s filte r
p a s s b a n d r e p lic a tio n s o f F

N y q u is t
fre q u e n c y

0 K N /2 K N
w = K p /D T w = 2 K p /D T

lo w - p a s s
d ig ita l filte r
^
F m

0 K N /2 K N
w = K p /D T w = 2 K p /D T

Figure 5: Digital low-pass filtering used to eliminate spectral replications introduced by extra
samples inserted into the waveform.

Figure 6 shows the complete time-domain interpolation scheme.


D T /K
D T

~ ^
f(t)
A n ti- a lia s in g f(t) S a m p le r K {fn } L o w - p a s s d ig ita l
lo w - p a s s filte r filte r
D T In s e rt K -1 z e ro s
F ( jW ) H ( jW ) = 0 , |W |> p /D T F ( jW ) H ( jW ) { fn } H (z ) i n t e r p o l a t e d
b e tw e e n s a m p le s
w a v e fo rm
c o n tin u o u s d o m a in d is c r e te d o m a in

D T /K

Figure 6: Real-time processing to interpolate a data stream by a factor K.

1.3 The Interpolation Filter


The ideal interpolation filter is a low-pass filter, operating at the high frequency rate, with a cut-off
frequency at the Nyquist frequency of the sampler ΩN = π/ΔT . The impulse response is therefore
sin (πn/K)
hn =
πn/K

5
which is clearly acausal. An FIR approximation to the ideal interpolator is obtained by truncating
hn to a finite length, say N = 2KM + 1, and delaying it by KM samples so that
sin (π (n − KM ) /K)
hn = n = 0, 1, 2 . . . N − 1
π (n − KM ) /K
and windowing with an appropriate window, for example a Kaiser or Hamming window. The
transfer function may be written
M
� −1
H(z) = bn z −n .
n=0
Figure 7 shows the complete interpolation scheme for an up-sampling factor K = 3.

i = 0 : f n 0 0 f n -1 0 0 . . .
i = 1 : 0 f n 0 0 f n -1 0 . . .
i = 2 : 0 0 f n 0 0 f n -1 . . .
f
fn K
K n + i
z -1
z -1
z -1
z -1
z -1
z -1
u p s a m p le

b 0 b 1 b 2 b 3 b 4 b 5 b b
M M -1
+ + + + + +
+ + + + + +
^
fK
+ +
n + i
s a m p lin g in te r v a l s a m p lin g in te r v a l
, T

Figure 7: Complete interpolation scheme (K=3), with an FIR interpolation filter.

1.4 Polyphase Interpolation Filtering


A substantial economy of computation may be achieved by the use of a polyphase filter structure.
As can be seen from Fig. 7, at each filter step many of the up-sampled data values are zero, and
do not contribute to the filter output. Therefore at each of the computation steps only a subset of
the filter coefficients are required. This leads to a structure involving a set of shorter filters applied
the original data sequence.
(1) Design an FIR interpolation filter of length M , based upon the up-sampling factor K.

(2) Form K ”sub-filters” from the filter coefficients bm , m = 0 . . . M − 1, by grouping them as


follows:

Sub-filter 0: b0 bK b2K b3K ...

Sub-filter 1: b1 bK+1 b2K+1 b3K+1 ...

Sub-filter 2: b2 bK+2 b2K+2 b3K+2 ...

... ... ... ... ... ...

Sub-Filter K-1: bK−1 b2K−1 b3K−1 b4K−1 ...

(3) At each major time step the interpolated data stream may be created by passing the data
sequence {fn } through each of the sub-filters, so that the interpolated value fˆKn+i is the
output of sub-filter i. The polyphase structure is shown in Fig. 8
Note that it is not necessary to perform the up-sampling step of inserting zero data points into the
data steam with this method.

6
^f
f n n K
s u b - filte r 0

^f
n K + 1
s u b - filte r 1

^f ^f
n K + 2 n K + i
s u b - filte r 2
, T /K

^f
(n + 1 )K -1
s u b - filte r K - 1

Figure 8: Polyphase filtering interpolation scheme.

2 Down-sampling (Decimation) by an Integer Factor


Decimation by an integer factor K is the reverse of interpolation, that is increasing the sampling
interval T by an an integer factor (or decreasing the sampling frequency). At first glance the process
seems to be simple: simply retain every Kth sample from the data sequence so that f˜n = fnK where
{f˜n } is the down-sampled sequence, as shown in Fig. 9. Caution must be taken however to prevent
aliasing in the decimated sequence. It is not valid to directly down-sample a sequence directly
unless it is known a-priori that the spectrum of the data set is identically zero at frequencies at
and above the Nyquist frequency defined by the lower sampling frequency.

, T L , T

t t
D o w n - s a m p le r

Figure 9: Basic temporal down-sampling by an integer factor L. Every Lth sample of the input
sequence is retained in the output; all other data points are “thrown away”.

In discussing sampling of continuous waveforms, we described the use of a pre-aliasing filter to


eliminate (or at least significantly reduce) spectral components that would introduce aliasing into
the sampled data set. When down-sampling, the digital equivalent is required: a digital low-pass
filter is used to eliminate all spectral components that would cause aliasing in the resampled data
set. The complete down-sampling scheme is shown in Fig. 10.

3 Up and Down-sampling with a non-integer factor


Assume that the goal is to re-sample a sequence by a non-integer factor p that can be expressed as
a rational fraction, that is
N
P =
M

7
, T , T L , T

t t

D ig ita l lo w - p a s s D o w n - s a m p le r
a n ti- a lia s in g filte r L

Figure 10: Temporal down-sampling by an integer factor L with a digital low-pass filter to eliminate
components in the input sequence that would cause aliasing through the down-sampling operation.

where N and M are positive integers. This can be achieved by (1) interpolation by a factor N ,
followed by (2) decimation by a factor M , as shown in Fig. 11(a). However, since the two low-pass
filters are cascaded, they may be replaced with a single filter with a cut-off frequency that is the
lower of the two filters as is shown in Fig. 11(b).

{ fn } u p - s a m p le r in te r p o la tio n filte r a n ti- a lia s in g filte r d o w n - s a m p le r ^


{ fm }
N H u p (z ) H d n (z ) M

in te r p o la tio n d e c im a tio n

(a )

u p - s a m p le r lo w - p a s s filte r d o w n - s a m p le r
{ fn } ^
N { fm }
H lp (z ) M

(b )

Figure 11: Combined interpolation/decimation to achieve re-sampling by a non-integer factor. In


(a) an interpolator and decimator have been connected in series. In (b) the two low-pass filters
have been replaced by a single filter with a cut-off trequency that is the lower of the two filters in
(a).

4 Matlab Functions for Resampling


Y = RESAMPLE(X,P,Q) resamples the sequence in vector X at P/Q times the original sample rate
using a polyphase implementation. Y is P/Q times the length of X (or the ceiling of this if
P/Q is not an integer). P and Q must be positive integers.

Y = UPFIRDN(X,H,P,Q) is a cascade of three systems applied to input signal X:

(1) Upsampling by P (zero insertion). P defaults to 1 if not specified.


(2) FIR filtering with the filter specified by the impulse response given in H.
(3) Downsampling by Q (throwing away samples). Q defaults to 1 if not specified.

UPFIRDN uses an efficient polyphase implementation.

Y = INTERP(X,R) resamples the sequence in vector X at R times the original sample rate. The
resulting resampled vector Y is R times longer, LENGTH(Y) = R*LENGTH(X).

8
Y = DECIMATE(X,R) resamples the sequence in vector X at 1/R times the original sample rate. The
resulting resampled vector Y is R times shorter, i.e., LENGTH(Y) = CEIL(LENGTH(X)/R).
By default, DECIMATE filters the data with an 8th order Chebyshev Type I low-pass filter
with cutoff frequency .8*(Fs/2)/R, before resampling.

Y = DOWNSAMPLE(X,N) downsamples input signal X by keeping every Nth sample starting with the
first. If X is a matrix, the down-sampling is done along the columns of X.

Y = UPSAMPLE(X,N) upsamples input signal X by inserting N-1 zeros between input samples. X
may be a vector or a signal matrix (one signal per column).

Appendix A: A Matlab Function for DFT Based Interpolation.


%-----------------------------------------------------------------------------­

% 2.161 MATLAB Example: Data interpolation (up-sampling) using the DFT

% Author: D. Rowell 4/14/07

% Usage: fout = dftupsample(f, K)

% where f is an input data record (real) of length N,

% fout is the output record of length KN, and K is the integer

% interpolation factor, that is (K-1) interpolated data

% points will be inserted between each of the original data points.

% Note: MATLAB does not require its FFT routine to be restricted to radix-2

% lengths. Therefore this function may be used for arbitrary length

% records f and interpolation factors K.

%----------------------------------------------------------------------------­

function fout = dftupsample(fin,K)

N = length(fin);

% Take the DFT

Fin = fft(fin);

% Create an extended empty array, and fill the ends with the upper and lower

% halves of the DFT. (Note that MATLAB arrays run from 1 to N)

Fout = zeros(length(Fin)*K,1);

Fout(1:N/2) = Fin(1:N/2);

Fout(N*K - N/2+1: N*K) = Fin(N/2+1:N);

% Take the inverse DFT, scale by K, and preserve the real part

fout = real(ifft(Fout))*K;

%----------------------------------------------------------------------------­

9
Example: The following MATLAB fragment creates a data record of length 8, then uses
dftupsample() to up-sample by a factor of K = 11:

>> i=[0:7];

>> f8=cos(2*pi*(i-1)/8) + 3*cos(4*pi*(i-1)/8)+ sin(6*pi*(i-1)/8) ;

>> f88 = dftupsample(f8,11);

>> subplot(2,1,1), stem([0:1:7],f8)

>> subplot(2,1,2), stem([0:1/11:87/11],f88)

>>

Plots of the input and output data sets are shown in Fig. 12.

−5
0 1 2 3 4 5 6 7 8
(a) time (s)
5

−5
0 1 2 3 4 5 6 7 8
(b) time (s)

Figure 12: Matlab example: (a) input data sequence of length 8, and (b) output data sequence of
length 88.

10

You might also like